SSH Passwordless Login

How to connect to a Linux ssh server without using a password?
Let’s imagine there is a “Server” with user “Admin” and we want to connect with our “client” machine with username “User”.
We need only three steps:

  1. Generate client key
  2. Check server config
  3. Upload key to server

Generate client key

To generate the key in the client, connect with “user” username and execute:

ssh-keygen -t rsa

It will ask you for some data, for the simplest config, just hit [Enter] three times.
The first question you asked was the path where the key was going to be stored. Usually in “.ssh/id_rsa” inside your home.

Check server config

Connect to the “Server” with user “Admin” and check if “.ssh” directory exists.

Upload key to the server

In the server, inside “.ssh” create or edit the file “authorized_keys” and add the content of the “id_rsa.pub” we have generated in the client.
Yo can do that in one step from the client this way:

cat .ssh/id_rsa.pub | ssh Admin@servername 'cat >> .ssh/authorized_keys'

 

Leave a Reply

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