How to login via SSH without password

Login to local machine where passwordless login should be used from

Generate public/private rsa keys on the local machine:

[root@local-host]# ssh-keygen

// or
[root@local-host]# ssh-keygen -t rsa

Copy public key to the remote machine using ssh-copy-id:

[root@local-host]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@remote-host

// or specify a different port if it's different than 22
[root@local-host]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@remote-host -p <port>

But I recommend to provide a port number before the host details, as some errors might occur for different reason, like:

/usr/bin/ssh-copy-id: ERROR: Too many arguments.  Expecting a target hostname, got: 

After entering the correct password for the remote host a message should be displayed like next:

...
Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '22' 'root@remote-host'"
and check to make sure that only the key(s) you wanted were added.

And that’s it actually.

Leave a Reply