闲来无事。想试下两台服务器SSH无密码连接。两台vm。一台IP:192.168.1.3.一台IP:192.168.1.151.现在想使用1.3登录1.151不需要密码。
1.使用root登陆到1.3上。使用dsa认证登陆到1.151.
# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (//.ssh/id_dsa):  按Enter
//.ssh/id_dsa already exists.
Overwrite (y/n)? y 因为已有文件。我选择覆盖。
Enter passphrase (empty for no passphrase): 我偷懒没有输入密码。Enter
Enter same passphrase again:
Your identification has been saved in //.ssh/id_dsa. 私钥文件
Your public key has been saved in //.ssh/id_dsa.pub. 公钥文家
The key fingerprint is:
48:6a:24:bc:d8:60:d4:59:5e:20:09:28:f8:5f:e1:3e root@
#
# cd /.ssh/
# ls
id_dsa          id_dsa.pub      id_rsa          id_rsa.pub      known_hosts
2.将公钥文件拷贝到1.151服务器上。
# scp id_dsa.pub admin@192.168.1.151:/home/admin/
Password:
id_dsa.pub                                                                                                  100% 1107     1.1KB/s   00:00   
3.使用root用户登陆到1.151服务器上。
hakase# cd /root/.ssh/
hakase#
hakase# cat /home/admin/id_dsa.pub > authorized_keys 创建authorized_keys。
4.在1.3服务器使用ssh登陆1.151. 成功!
# ssh 192.168.1.151
Last login: Tue Nov 25 17:46:51 2008
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
        The Regents of the University of California.  All rights reserved.
FreeBSD 6.1-RELEASE (MYKENEL) #0: Tue Dec 25 17:18:48 CET 2007
Welcome to Hakase's PC!