Monday, April 27, 2009

Automatic login with ssh without a password - Linux

Install a ssh client

sudo apt-get install ssh

  1. Login to the ssh server with your client.

  2. Generate your key pair using the following command: (Don't use any passphrase)

    sahab@xxxx:~$ ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/sahab/.ssh/id_rsa):
    Created directory '/home/sahab/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/sahab/.ssh/id_rsa.
    Your public key has been saved in /home/sahab/.ssh/
    The key fingerprint is:
    2a:23:a3:f8:6c:af:3f:7e:12:b4:6a:80:98:c0:f3:ea sahab@gis
    The key's randomart image is:
    +--[ RSA 2048]----+
    | |
    | |
    |. |
    |.o . |
    |+.o. . S |
    |= .o . |
    | .+.o.. |
    |.++ooo. |
    |+E+=++ |
    sahab@xxx:~$ cd ~/.ssh
    sahab@xxx:~/.ssh$ cat >> authorized_keys
    sahab@xxx~/.ssh$ chmod 600 authorized_keys
  3. Log out of the server and go back to your local shell

    $ cd
    $ cd .ssh
  4. Copy the file id_rsa that was generated on the server into this directory. You can use sftp or scp for this.

sahab@sahab-desktop:~/.ssh$ sudo scp -r sahab@xxx:/home/sahab/.ssh/id_rsa

     $ cd .ssh
$ chmod 600 id_rsa

You should now be able to login via ssh without having to prompt for a password.


marry said...

Blogs are so informative where we get lots of information on any topic. Nice job keep it up!!

International Finance Dissertation

ulGeN said...

This was what i was looking. I'm almost tired of copying ssh passwords :)

Great article. Clean, simple and right to-the-point.

Much thanx

karl said...

How would I do this if I wanted multiple servers that I didn't want to enter a password for?