Wednesday, December 16, 2009

How to ssh without password

Sometimes we need to remotely copy and backup files to a backup server every night. In linux, it is very easy to do so.

Here's how...

At local host, generate ssh key.

1. guest@guest:~$ ssh-keygen -t rsa
2. Generating public/private rsa key pair.
3. Enter file in which to save the key (/home/guest/.ssh/id_rsa):
4. Enter passphrase (empty for no passphrase):

5. Enter same passphrase again:
Your identification has been saved in /home/guest/.ssh/id_rsa.
Your public key has been saved in /home/guest/.ssh/id_rsa.pub.
The key fingerprint is:
0c:51:be:1e:2d:1c:8f:34:18:b9:8e:21:a3:50:6e:95 guest@guest

After that, at the remote linux host, copy the file in /home/guest/.ssh/id_rsa.pub

Create directory .ssh

1. myhost@myhost:~$ mkdir .ssh
2. From guest, guest@guest:~$ scp ~/.ssh/id_rsa.pub myhost@myhost:~/.ssh/authorized_keys
3. Change to file permission, myhost@myhost:~$ chmod 600 .ssh/authorized_keys
4. Then now you can ssh into the myhost without any password.
5. guest@guest:~$ ssh myhost@remoteIPaddress
6. guest@myhost:~$ 


Then, you are ready to go...

No comments:

Post a Comment