Why is this required ?
– if you hate password prompt 🙂
– For automation scripts copying data using scp, sftp
Lets assume two machines
local with user “manish”
remote with user “autouser”
Step 1 :
Generate public/private key pair on “local” host
manish@local$ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/manish/.ssh/id_dsa):
Created directory ‘/home/manish/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/manish/.ssh/id_dsa.
Your public key has been saved in /home/manish/.ssh/id_dsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx manish@local
Note: Don’t give any password/passphrase for key
Step 2:
copy “local” host Public key to “remote” host using scp
manish@local$ scp /home/manish/.ssh/id_dsa.pub sunone@remote$:/home/autouser/
Step 3:
Login to remote machine as “autouser” and do this
append “local” host’s public key to “authorized_keys” keys of “remote” host
autouser@remote$ cat ~/id_dsa.pub >> ~/.ssh/authorized_keys
Change permission of file authorized_keys on “remote” host
autouser@remote$ chmod 600 ~/.ssh/authorized_keys
Step 4:
done, test it, try ssh
manish@local$ ssh -lautouser remote
autouser@remote$
Lets try scp
manish@local$ ls -l
total 0
-rw-r–r– 1 manish home 0 Nov 6 14:18 test
manish@local$ scp test autouser@remote:/home/autouser/
test 100% |*****************************| 0 00:00