[root@xyly ~]# ifconfig eth0 | awk ‘/inet addr/{print }’
inet addr:192.168.72.11 Bcast:192.168.72.255 Mask:255.255.255.0</p> <p>[root@xyly ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #密钥报存的位置和名称
Enter passphrase (empty for no passphrase): #密钥为空
Enter same passphrase again: #再一次输入
Your identification has been saved in /root/.ssh/id_rsa. #私钥的位置
Your public key has been saved in /root/.ssh/id_rsa.pub. #公钥的位置
The key fingerprint is:
04:c5:7a:57:f6:2e:9c:1f:b5:e7:45:b3:11:f3:c7:18 root@xyly
公钥已经生成
现在把公钥上传到另一台服务器上去。
代码如下:
[root@xyly ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.72.129
The authenticity of host ’192.168.72.129 (192.168.72.129)’ can’t be established.
RSA key fingerp
rint is 3b:26:19:2e:51:ca:cc:de:ac:bc:00:09:f0:7c:7d:f1.
Are you sure you want to continue connecting (yes/no)? yes #由于是第一次登录,服务器要进行确认
Warning: Permanently added ’192.168.72.129′ (RSA) to the list of known hosts.
Address 192.168.72.129 maps to localhost, but this does not map back to the address – POSSIBLE BREAK-IN ATTEMPT!
root@192.168.72.129′s password:
Now try logging into the machine, with “ssh ‘root@192.168.72.129′“, and check in:</p> <p>.ssh/authorized_keys #把公钥上传的位置和公钥的文件名</p> <p>to make sure we haven’t added extra keys that you weren’t expecting.
[root@xyly ~]# ssh 192.168.72.129
Address 192.168.72.129 maps to localhost, but this does not map back to the address – POSSIBLE BREAK-IN ATTEMPT!
Last login: Thu Aug 4 18:08:05 2011 from 192.168.72.1
[root@localhost ~]#
现在不用输入密码,就可以登录了。退出登录
代码如下:
[root@localhost ~]# exit
logout
Connection to 192.168.72.129 closed.
linux ssh 密钥认证无需输入密码即可登录,在设置密钥的同时,也可以输入密码,即可密码+密钥认证就可以完成!