Centos

SSH login without Password

January 28th 2012 | Posted by

There have been a number of times I’ve found myself needing to SSH from server to server and would prefer not to use a password.

After running two simple commands you can SSH to a server without requring your username or password. The basic principal is to generate a public/private key pair which is associated with your user account. The public key is then copied to the destination server and used for authentication instead of your password.

In this example I assume you will be connecting from servera and connecting to serverb.

  1. From servera you will need to run ssh-keygen. This generates the public/private key pair

    alan@servera$<strong> ssh-keygen </strong>Generating public/private rsa key pair.
    Enter file in which to save the key (/home/alan/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/alan/.ssh/id_rsa.
    Your public key has been saved in /home/alan/.ssh/id_rsa.pub
  2. Use ssh-copy-id to copy the generated public key to serverb. This will append your public key to the list of authorised keys on the remote server in ~/.ssh/authorized_keys

    alan@servera$ <strong>ssh-copy-id -i ~/.ssh/id_rsa.pub serverb</strong>
    alan@serverb's password:
    Now try logging into the machine, with "ssh 'serverb'", and check in:
    
    .ssh/authorized_keys
    
    to make sure we haven't added extra keys that you weren't expecting.
  3. Now try and SSH to serverb
    alan@servera$ <strong>ssh serverb</strong>
    Last login: Sat Jan 28 10:01:59 2012 from 10.30.0.155

Assuming you followed the above steps correctly you should now be able to SSH to your server without requring a password!

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>