Generate Public Key For User Linux

Lets say you have a private/public key pair that you use to login to your server via SSH and you lose the public key, either it was deleted or corrupt and you don’t want to have to regenerate a new pair what options do you have? In this post I will demonstrate how to regenerate a public key from the corresponding private key that you still have. Write down the various generations of computer with key characters.

I'm trying to create an ssh key for another user. I'm logged in as root. If you generate the key for the user you also have to have a secure method of getting the private key and it's pass phrase to the user. Much better the user generate the key and then just email you the public key. Using SSH public-key authentication to connect to a remote system is a robust, more secure alternative to logging in with an account password or passphrase. SSH public-key authentication relies on asymmetric cryptographic algorithms that generate a pair of separate keys.

Generate public key and store into a file

Home Linux Basics: How To Create and Install SSH Keys on the. How To Create and Install SSH Keys on the Shell. The public key can now be traced to the link.

It is a simple one liner command to generate a public key from a private key, so lets say our private key is named ‘user@myserver.key’ and we want to generate the public key and name it ‘authorized_keys’. Below is the command to do this.

For

‘-f user@myserver.key’: references the key file user@myserver.key to generate the public key from

‘> authorized_keys’: instead of printing the output to the console redirect the output (public key) to a file named ‘authorized_keys’

Generate Public Key For User Linux Password

Copy public key to your server

Now we will need to take our authorized_keys file and store it on the server, if we can currently login via SSH to our server we can use rsync over ssh to securely copy the public key to the server, Although this key is displayed to anyone who attempts to login to your server it is smart to use SSH or another secure method to copy it up to the server to ensure that the key is not tampered with while it is being transmitted.

Below is an example using rsync to copy the authorized keys file to its destination on the server and removing it from your local computer.