SSH Password-less connection to remote system

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

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/
The key fingerprint is:
xx:yy:zz:ii user@MACHINE

Create ( if not already done ) the .ssh folder on the local machine from the remote machine
ssh mkdir -p .ssh

Upload the remote machines generated public keys to the local machine
cat .ssh/ | 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...

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 "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...

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

When finished you can log on to the remote machine, from the local machine without password

Was this article helpful?

Yes No

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

Last updated on January 8, 2017 with 650 views