SSH: Password-less access (Linux)

Categories: Howto, Linux

I am sure like me most of you run a development desktop (linux or windows) & run a separate test server (mostly linux). By Linux, I mean *NIX flavor. One of the most irritating aspect of this configuration is the frequent copying of code/binaries to & fro. This is very irritating. There are many solutions to make it less painful like NFS mount etc.. But most often than not, we end up doing ‘scp’ across these system more frequently than we would like it to be.

So here is the one simple method to reduce the pain: use public-private key combination to enable password less access.

Create public and private keys

Use the tool ‘ssh-keygen,’ which generates, manages & converts authentication keys for ssh. The usage is as below:

local-user@local-box$> ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/local-user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/local-user/.ssh/id_rsa.
Your public key has been saved in /home/local-user/.ssh/
The key fingerprint is:
d7:98:b5:e7:70:70:26:a3:d0:13:e5:17:71:bc:31:90 local-user@local-box
The key's randomart image is:
+--[ RSA 2048]----+
|          ....=o.|
|         . o E =.|
|        . o * + +|
|         . B O . |
|        S = + o  |
|         .   =   |
|              .  |
|                 |
|                 |

Next step is…

Copy the public key to remote host

For this, we can use ‘ssh-copy-id,’ which is a script (in my box it is available at /usr/bin/ssh-copy-id) to install your public key(s) on a remote machine.

local-user@local-box$> ssh-copy-id -i ~/.ssh/ remote-user@remote-box
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
remote-user@remote-box's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'remote-user@remote-box'"
and check to make sure that only the key(s) you wanted were added.


local-user@local-box$> ssh remote-user@remote-box
Linux remote-box 2.6.32-53-server #115-Ubuntu SMP Wed Oct 23 07:54:54 UTC 2013 x86_64 GNU/Linux
Ubuntu 10.04.4 LTS

Welcome to the Ubuntu Server!
 * Documentation:

  System information as of Tue Dec  3 16:00:42 YEKT 2013

  System load:  0.04               Processes:           74
  Usage of /:   24.4% of 61.60GB   Users logged in:     1
  Memory usage: 44%                IP address for eth0:
  Swap usage:   0%

  Graph this data and manage this system at

New release 'precise' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Tue Dec  3 11:58:52 2013 from local-user@local-box

Voila!!! šŸ™‚


    Leave a Reply

    Your email address will not be published.