search by tags

for the user

adventures into the land of the command line

setting up ssh keys for passwordless authentication

you can generate a set of ssh keys by running this command

$ ssh-keygen -t rsa

if you just press enter at the prompt, this will generate a private and public key inside your home:

$ ~/.ssh/id_rsa
$ ~/.ssh/

the private key “id_rsa” stays where it is and should have a passphrase, but you don’t have to

Enter passphrase (empty for no passphrase):

the public key “” can be copied to your home directory on the remote host by doing:

[[email protected] ~]$ ssh-copy-id -i ~/.ssh/ remotehost
[[email protected] ~]$ ssh-copy-id -i ~/.ssh/ [email protected]_host

this will create an .ssh directory in you home on the remote host and the public key will be copied inside with the name “authorized_keys” permissions will also be set to 700 for the directory and 600 for public key

there will be another file in ~/.ssh called known_hosts, which contains a list of known hosts that have logged in before along with the contents of the public key

[[email protected] ~]$ ls -al
drwx------ 2 user group 4096 Aug  25  2015 .ssh

[[email protected] ~]$ ls -l .ssh
-rw------- 1 user group 404 Aug  25  2015 authorized_keys
-rw-r--r-- 1 user group 824 Aug  25  2015 known_hosts

you can login to the remote host:

[[email protected] ~]$ ssh remotehost
[[email protected] ~]$ ssh [email protected]

the first time you log on, you will be prompted for a password. your password will be saved and associated with the key, from then on allowing you to log in without being prompted for a password

this will allow you to do all sort of funky things, if not make your life a little bit easier if you routinely manage large or small numbers of remote hosts