You want to use Linux/AIX/Unix and OpenSSH to
atomize your tasks. Therefore you need an automatic login from hostA as user a
to hostB as the same user. You don’t want to enter any passwords, because (for
example) you want to call ssh from a within a shell script.
First log in on hostA as user a and generate a
pair of authentication keys. Do not enter a passphrase:
#
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key
(/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in
/home/a/.ssh/id_rsa.
Your public key has been saved in
/home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 ....
Now use ssh to create a directory ~/.ssh as on
hostB (the directory may already exist, which is fine):
#
ssh user@hostB mkdir -p .ssh
user@hostB's password:
Finally append a’s new public key to
user@B:.ssh/authorized_keys and enter b’s password one last time:
#
cat .ssh/id_rsa.pub | ssh user@hostB 'cat >> .ssh/authorized_keys'
user@hostB's password:
From now on you can log into hostB as “user” from
hostA as a without password:
# ssh user@hostB hostname
Depending on your version of SSH you might also
have to do the following changes:
Put the public key in .ssh/authorized_keys2
Change the permissions of .ssh to 700
Change the permissions of .ssh/authorized_keys2 to
640
njoy the simplicity.......
Atul Singh
No comments :
Post a Comment