rsync同步或ssh ip时需要输入服务器密码,可以通过如下操作实现无密码安全操作。
1.产生公匙文件,注意不要输入passphrase
[wm@adx .ssh]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/wm/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/wm/.ssh/id_dsa.
Your public key has been saved in /home/wm/.ssh/id_dsa.pub.
The key fingerprint is:
9b:fc:6f:fc:7f:4b:22:8f:9f:db:91:ef:3f:39:b0:6f wm@adx
[wm@adx .ssh]$ ls -al
total 28
drwx------ 2 wm wm 4096 Oct 22 10:15 .
drwxrwx--- 9 wm wm 4096 Oct 22 10:01 ..
-rw------- 1 wm wm 668 Oct 22 10:15 id_dsa
-rw-r--r-- 1 wm wm 596 Oct 22 10:15 id_dsa.pub
-rw------- 1 wm wm 1671 Sep 28 19:01 id_rsa
-rw-r--r-- 1 wm wm 388 Sep 28 19:01 id_rsa.pub
-rw-r--r-- 1 wm wm 1211 Oct 21 18:09 known_hosts
-t type
指定要创建的密钥类型。可以使用:"rsa1"(SSH-1) "rsa"(SSH-2) "dsa"(SSH-2)。
提示创建.ssh/id_rsa、id_rsa.pub的文件,其中第一个为密钥,第二个为公钥。
2.将公钥文件传送到需要登陆的服务器
[root@adx ~/.ssh]# scp id_rsa.pub root@192.168.1.25:/data/
[root@adx ~/.ssh]# ssh 192.168.1.25
Last login: Wed Oct 22 08:33:44 2014 from 192.168.1.151
4.将刚才的公钥文件内容添加到用户的.ssh目录下的authorized_keys文件中
[root@tadx data]# cat id_rsa.pub >> /root/.ssh/authorized_keys
5.退出后再次登录,不需要密码。