Passwordless SSH

From SysadminPunk Wiki!

Jump to: navigation, search

Easiest Method

  1. Create SSH Key
username@localhost:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):  (Blank)
Enter same passphrase again: (Blank)
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
21:6a:c3:73:23:b4:b5:78:78:XX:14:c3:d5:5b:4c:ef username@server
The key's randomart image is:
+--[ RSA 2048]----+
|       .=o+=o++=.|
|        .++oo.=.o|
|        . oo ..o.|
|       o+oo   E .|
|      . S  ..o.  |
|                 |
|                 |
|                 |
|                 |
+-----------------+
  1. Now copy Key to server of choice
username@localhost:~$ ssh-copy-id -i ~/.ssh/id_rsa.pub username@server
username@server's password:
Now try logging into the machine, with "ssh 'username@server'", and check in:
 .ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
  1. Now log on to new server to test!
username@localhost:~$ ssh username@server
Linux server 2.6.26-1-amd64 #1 SMP Fri Mar 13 17:46:45 UTC 2009 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright. 
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have new mail.
Last login: Wed Jul  1 08:56:25 2009 from im.auctiva.com
username@server:~$ exit

Redo key and re-upload

  1. If perhaps you need to redo your ssh key do the following:
username@localhost:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
/home/username/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): (Blank)
Enter same passphrase again: (Blank)
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
7d:ad:d9:c8:1b:e3:58:31:1b:39:4c:32:2c:6e:e4:7b username@server
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|      . o .      |
|       . = .     |
|      + E.B      |
|     = oS*.*.    |
|      =   .+.+   |
|     .    .o= .  |
|  +       ....o  |
|           .+o   |
+-----------------+
username@localhost:~$ ssh username@server "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
username@server's password:
username@server:~$
Personal tools