Setting up public key authenticationArticle ID: 85
ON THIS PAGE
RESOLUTION
Setting up public key authentication for a user account
- To setup public key authentication for your user account, make sure you are logged into shell and remove the .ssh directory if it exists by executing the following command:
rm -r -f ~/.ssh
. This will remove the current public and private keypair if any, to ensure that they don't interfere with the ones we are going to create. - Create a new private/public rsa keypair by executing the following command:
ssh-keygen
and make sure that you save the keys inside the .ssh directory (the command will automatically create the directory if it's not found). Example:[ricardo@linuxshell ~]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/ricardo/.ssh/id_rsa): Created directory '/home/ricardo/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ricardo/.ssh/id_rsa. Your public key has been saved in /home/ricardo/.ssh/id_rsa.pub
Remark The public/private rsa keypair will be saved into the .ssh directory if you leave their location field blank. - Rename the generated public key to authorized_keys to tell the system to use this public key to validate future public key authentications. To do this, execute the following command assuming that id_rsa.pub is the name of the public key:
mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
- Download the generated private key (/home/ricardo/.ssh/id_rsa in the above example) using SFTP and use it to login using public key authenticationNotice that You may be asked to enter a passphrase if you have provided one while creating the private key.
Did you find this helpful?