How to log into a Linux server without a password

Let’s assume we have two Linux systems, client and server.

On the client, carry out the following steps

  • ssh-keygen
  • By default saves to /home/username/.ssh/id_rsa
  • Enter a passphrase (if you want to add one to the key)
  • ssh-copy-id root@server (replace root@server with your user name and server IP or host name)
  • You should get prompted for the server’s password, enter this and the key will be copied

To test everything worked, execute the following

ssh root@server

(obviously, replacing root@server with your user name and server IP or host name) and if all worked you should log into the server without having to enter a password.

Now for each server that you need ssh access without a password, simple run ssh-copy-id root@server with the username and server that you want to connect to.