SSH Password-less connection to remote system

Author Johnny Josefsson on March 1, 2015 | Print | Bookmark
1)
Log on with SSH to the remote machine

2)
Create authentication SSH key on the remote machine (per user / remote machine)
ssh-keygen -t rsa Don't set a password at all, or just run to make that automatically with the ""
ssh-keygen -t rsa -P ""

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Created directory '/home/user/.ssh'.
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
xx:yy:zz:ii user@MACHINE

3)
Create ( if not already done ) the .ssh folder on the local machine from the remote machine
ssh user@domain.top mkdir -p .ssh

4)
Upload the remote machines generated public keys to the local machine
cat .ssh/id_rsa.pub | ssh user@local.machine 'cat >> .ssh/authorized_keys'
There are no problem to run the above command from several remote machines, they will be added (not overwritten) in the authorized_keys file
You can also copy and paste the key manually with vi or nano. If using nano, then add the flag -w as not to have line breaks

THIS SHOULD ALSO BE DONE VICE VERSA e.g. from the local machine to the remote machine...

5)
Set permissions on the .ssh folder and the authorhized_keys on the local machine from the remote machine (if not done properly it will continue asking for password)
ssh user@domain.top "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

Or manually... chmod 700 .ssh chmod 640 .ssh/authorized_keys

This should also be done vice versa...

6)
On remote machine where it should work the SSHd config must be correct of allowing both "user" logon and Public Key authentication
1) AuthorizedKeysFile %h/.ssh/authorized_keys
2) StrictModes off

7)
When finished you can log on to the remote machine, from the local machine without password
ssh user@domain.top


Was this article helpful?

Yes No

Category: Scripting, Linux, SSHd, OS X, Authentication

Last updated on January 8, 2017 with 722 views