How to Generate SSH Keys in Linux

Generate SSH keys for setting up SSH Key Authentication

In this guide, I will show you how to generate a private/public ssh key pair using Linux Ubuntu. SSH keys offer a very robust and more secure alternative to password based login.

Most Linux distros come with a built-in ssh key generator (ssh-keygen) that you can access from the command line.

Generate Public/Private SSH Key Pair

Open the command terminal. You can use the shortcut Crtl + Alt + T.

In the command prompt, use the ssh-keygen command and supply your email address as follows:

ssh-keygen -C “youremail@xxx.com”

When prompted for file to save your key in, you can add a directory path or leave the default.

In this example, I use the following file /home/mwiza/.ssh/id_rsa. Where id_rsa is the file in which the private key is saved. Where mwiza my username on my system.

When done. Your output will be similar to the one below.

In addition, to the id_rsa private key file another file named id_rsa.pub will be generated.

Image for post
Image for post

Open public key

Now head over to the directory in which the key pair file was generated. Open the id_rsa.pub file with a text editor of your choice.

Copy all content of the id_rsa.pub file as it appears below and paste into the interface provided by your remote server client.

ssh-rsa AAAAB3NzaC1ycfsgsfgsgsksgAQABAAABAQDfHEiJHGit1HB04b/H8TPLMxMtFtTXsPN+f3pg3/DJFKDFJDFDFDFDFDFFdfgfgfgfsgH/k+fgAOzAVI9n9UR5R3FDxVXsJOv6ASMtbto3bjbjwFj0bwunUWFO/0uKvBsjftUzj5mwL8emrk7rShN5zSQBvzAqRCCVXd0e+KNZSZO00KwAgexQJhsKyqummIa+5fcXk4Jzn5geerleGZk3iNaI4ztJdxQLgMrNrG6rEQRqM0StzcXMnfdfdwUj2CFwO0sdfafafafgsgskHHHSHHDSHDSHDHSDHDS+uBej4Ok/VGaDuV youremail@xxxx.com

In the picture below is an example interface to accept a public key, from Azure DevOps.

Image for post
Image for post

Conclusion

That’s it. it’s very easy to generate SSH keys using the ssh-keygen command. Newer versions of windows also come with a built-in ssh-keygen command tool, which is a nice alternative to generating SSH keys via putty.

Written by

I develop software by profession. My interests include: history, economics, politics & enterprise-architecture. I am a child of God.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store