Thursday, April 21, 2011

SSH

To generate ssh private and public key

[chris@rhel01 .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/chris/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/chris/.ssh/id_rsa.
Your public key has been saved in /home/chris/.ssh/id_rsa.pub.
The key fingerprint is:
8c:23:99:93:4a:6d:27:9c:7b:92:07:aa:49:5d:6a:87 chris@rhel01.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| o = o |
| . &.+ S |
| ..++O . |
| .oE+.o |
|.o. .+ |
|o |
+-----------------+

This will create under ~/.ssh id_rsa.pub public key to copied to the remote system and id_rsa private key for your local system

The best way to copy id_rsa.pub into a remote system is to use scp-copy-id This command will automatically create authorized_keys under ~/.ssh/
#scp-copy-id -i /home/chris/.ssh/id_rsa rhel02
The authenticity of host 'rhel02 (192.168.1.201)' can't be established.
RSA key fingerprint is 01:91:64:15:5b:64:fa:90:bb:b5:63:5e:f8:7e:73:71.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'rhel02,192.168.1.201' (RSA) to the list of known hosts.
chris@rhel02's password:
Now try logging into the machine, with "ssh 'rhel02'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[chris@rhel01 ~]$ ssh rhel02
Last login: Fri Apr 8 03:23:42 2011 from rhel01
chris@rhel02.localdomain: ~ $

I tried to remove all files under ~/.ssh and the authorized_keys on the destination server. Re-do everything but when tried to ssh again, it gives me this error

[chris@wk ~]$ ssh rhel01
Agent admitted failure to sign using the key.

One solution was to use "ssh-add" command

[chris@wk ~]$ ssh-add
Identity added: /home/chris/.ssh/id_rsa (/home/chris/.ssh/id_rsa)
[chris@wk ~]$ ssh rhel01
Last login: Sat Jul 9 08:43:50 2011 from 192.168.122.1
[chris@rhel01 ~]$

No comments:

Post a Comment