The other day I got a new laptop and needed to generate ssh key pair. Sometimes you forget basic commands when you don’t run them on a daily basis. So, I took a short walk in Brooklyn, New York City before I started working on my new laptop setup.

To generate ssh key pair in Linux is quite simple. Use the ssh-keygen command. Open your Terminal and type:

ssh-keygen -t rsa

Next, you will need to specify the location of the file where you want to save the key such as for example:

Enter file in which to save the key (/home/youruser/.ssh/id_rsa):

Don’t type anything to leave your key at the default location with the default name /home/youruser/.ssh/id_rsa. If you want to you can specify a different name. I do this when I need to ssh to different servers, this helps me keep organized.

Finally, you will need to type a password if you like:

Enter passphrase (empty for no passphrase):

I usually leave it empty, but this is really up to you.

This will create a private key written to: /home/youruser/.ssh/id_rsa 

and a public key written /home/youruser/.ssh/id_rsa.pub

Copy the contents of your .pub file into your server’s .ssh/authorized_keys

Now you should be able to SSH to your server without using a password. Give it a try and Contact me if you have any questions.

Leave a comment

Your email address will not be published. Required fields are marked *