Thursday, November 5, 2009

SSH - if entering password annoys you...

You can avoid of entering remote host password every time you are logging on a host. It is very simple. Just follow the below steps.

Client side:
1. Generate new keys by using ssh-keygen command

waldekd@waldekd-desktop:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/waldekd/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/waldekd/.ssh/id_rsa.
Your public key has been saved in /home/waldekd/.ssh/id_rsa.pub.
The key fingerprint is:
12:da:79:13:03:32:4b:5d:9f:56:80:dc:f7:44:3a:1a waldekd@waldekd-desktop
The key's randomart image is:
+--[ RSA 2048]----+
| +..o.o..... |
| . +..o..o... |
| . . o E.oo |
| o o + o .. |
| . + S . |
| o . |
| |
| |
| |
+-----------------+

Don't enter any passphrase because if you do you will have to enter it every time you log. This operations generate a set of files inside of /home/your_login/.ssh/ directory.

2. Copy id_rsa.pub file on server. You can do it by log on server and get the appropriate file from the client

waldekd@waldekd-laptop:~$ scp waldekd@192.168.0.100:/home/waldekd/.ssh/id_rsa.pub .
ssh: connect to host 192.168.0.100 port 22: Connection refused
waldekd@waldekd-laptop:~$ scp waldekd@192.168.0.100:/home/waldekd/.ssh/id_rsa.pub .
id_rsa.pub 100% 405 0.4KB/s 00:00

3. Add information from the file to authorized_keys2 file

waldekd@waldekd-laptop:~/.ssh$ cat ../id_rsa.pub > authorized_keys2

4. Test

waldekd@waldekd-desktop:~/Documents$ ssh -C waldekd@192.168.0.101
Linux waldekd-laptop 2.6.27-15-generic #1 SMP Tue Oct 20 06:52:09 UTC 2009 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
Last login: Thu Nov 5 17:47:31 2009 from 192.168.0.100

5. Make fun :)

No comments:

Search This Blog