Passwordless SSH

Published 4/21/2016 02:18:26 AM  |  Last update 4/21/2016 02:40:29 AM
Tags: ssh, passwordless, cluster computing

SSH (Secure Shell) is a common protocol for remote access to *nix systems. It usually requires authorization using username and password, which is, however, quite unhandy for cluster computing. Therefore, an easy and effective way to get rid of SSH login password issue is what to be discussed in this article. Please note that the article will cover only OpenSSH version 2 in the demonstration section.

You can find short informations e.g. on this site. All SSH data for your account are stored in the directory ~/.ssh ("~" means: your home directory, most likely something like /home/yourlogin). For login without password, the SSH program needs something to identify you. This is done via a pair of encrypted files: a private and a public key. First you have to create this pair of files with the command:

ssh-keygen -t rsa

The suggested location is most likely correct, the command should offer your SSH data directory (i.e. the directory ~/.ssh, see above). If asked for a pass phrase, do not enter one! (If you would, you have to type the pass phrase on each login - which most likely would not be a real improvement to typing your password) The command will create two files (id_rsa and id_rsa.pub) in the SSH data directory. The first file contains your private key, the second file contains your public key. These files authorize yourself even without password. You should change the permissions for these two files using the following commands.

cd ~/.ssh

As your private key is the "opener" for the public key, it have to be restricted for yourself: chmod go-rwx id_rsa # restrict access to private key chmod a+r id_rsa.pub # everybody may access your public key The public keyfile should now be copied to the file authorized_keys containing information on machines allowed to connect without password:

cat id_rsa.pub >> authorized_keys

Please use two ">", as this will append the content of the file id_rsa.pub to the file authorized_keys. One ">" would overwrite it. Now, you can connect without password to your local machine:

ssh localhost

The generated public key has to be appended to the file authorized_keys on any machine you want to connect without password.

© 2024 blog.tinyray.com  by tinyray