Enabling Password-less SSH

In setting up a local Hadoop stack, you’ll need to enable SSH access to your machine from your machine. This is also useful for other systems, so a good thing to know in general. The following instructions will guide you through setting it up on a Linux box, but can also be applied to Mac OSX.

If your distro doesn’t have ssh (attempt to log into localhost via ssh localhost and connection is refused), you need to install OpenSSH. Or, do the following:

ubuntu$ sudo apt-get install openssh-server [sudo] password for greys:
 Reading package lists... Done
 Building dependency tree
 Reading state information... Done
 Suggested packages:
   rssh molly-guard openssh-blacklist openssh-blacklist-extra
 The following NEW packages will be installed:
 0 upgraded, 1 newly installed, 0 to remove and 75 not upgraded.
 Need to get 285kB of archives.
 After this operation, 782kB of additional disk space will be used.
 Get:1 http://ie.archive.ubuntu.com jaunty/main openssh-server 1:5.1p1-5ubuntu1 [
 Fetched 285kB in 0s (345kB/s)
 Preconfiguring packages ...
 Selecting previously deselected package openssh-server.
 (Reading database ... 101998 files and directories currently installed.)
 Unpacking openssh-server (from .../openssh-server_1%3a5.1p1-5ubuntu1_i386.deb) .
 Processing triggers for ufw ...
 Processing triggers for man-db ...
 Setting up openssh-server (1:5.1p1-5ubuntu1) ...
 Creating SSH2 RSA key; this may take some time ...
 Creating SSH2 DSA key; this may take some time ...
  * Restarting OpenBSD Secure Shell server sshd

Now, to setup the password-less ssh, we need to use public and private keys.

$ 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:
     23:7b:df:10:fb:85:33:1a:fc:34:ec:db:60:ce:93:78 [user]@ubuntu

Next, add the public key to the set of authorized_keys, thus enabling SSH to the machine.

$ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys

Lastly, test it out!

$ ssh localhost

If this fails, you may need to try the following:

$ echo "IdKey id_rsa" > ~/.ssh/identity
$ chmod 644 ~/.ssh/identity

One thought on “Enabling Password-less SSH

Leave a Reply

Your email address will not be published. Required fields are marked *