Login to server or systems using SSH keys

You might be working with a system, maybe with servers or with other machines, which you may need to login to. So, you have two ways to to login to remote systems. After creating a user in the systems with password, you can login to that system with password or you can set SSH keys.

Image source

When you choose to login to machines using ssh keys, you don’t need to put in password on each logins. When the key pair combination matches, you will be automatically logged in.

On choosing ssh based login, you will need to generate keys and setup private key in client machine and public key in server machine.

You may need to install openssh in your system in order to connect or to use ssh in your server in order to connect other system. You can do install with below command.

sudo apt install openssh-server

Use below command to generate ssh key. Generate keys in your local or the client machine. It will ask the locations where the key needs to be stored and stuffs. So, just keep default values. The keys will be stored in ~/.ssh/ directory.

ssh-keygen -m PEM -t rsa -C “your_email@example.com”

Now you will have a public key and private key generated. Now, you will need to copy the public key to server. The private key will be in your client machine.

Do a — cat ~/.ssh/id_rsa.pub — This will produce output of the file. Now copy the content. Login to the server now. Create a directory .ssh in your home directory. Create a file authorized_keys. Now open the file and paste the content into the file.


You are done. Now, you can authenticate to servers using ssh and do hassle free logins to the system.


  1. If you see ssh-keygen not found, run below command to install openssh client in your machine. sudo apt install openssh-client.
  2. Some server may have disabled ssh login, you can enable in

Start-up and tech enthusiast. I write about Tech, Devops and anything related.

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