Private and Public keys are used to provide the logging mechanism into remote machines using SSH. These keys can be generated using ssh-keygen command. This can be done on any unix based systems, such as Linux or FreeBSD. To generate keys, type the following command in the terminal window.

ssh-keygen –t rsa

OR

ssh-keygen –t dsa

Now you will be asked where to store the file in which these keys will be stored. Default location to store this file is in .ssh/id_rsa or .ssh/id_dsa directory, which is present in your home directory. In my case it is stored inside /home/realin/.ssh/id_rsa . If you do not want to change the default location, hit enter and now you will asked to enter a passphrase. Enter the passphrase of your choice and hit enter. You will asked to re-enter passphrase to confirm.

That shall be all to create the keys. This will create files like id_rsa.pub for public key, id_rsa for private key. Now you can share your public key as required.

Changing the comment in public key

If you saw your public key, then you would have notice that at the end of the key there is a comment. By default this comment is like user@hostname , but you can change this comment using the following command.

ssh-keygen –t rsa –C “My nice comment”

Some clients like PuTTY, shows it when the user is logged in via SSH.

Hope that helps.

Stay Digified !!
Sachin Khosla

Share this post: