看了 IBM Developers 方法如下:
假如用户为 user,主机为 host,要登陆的机器(也就是开 sshd 的机器)为 remote 则:
[code:1]
user@host# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
(hit enter)
Enter passphrase (empty for no passphrase):
(enter a passphrase)
Enter same passphrase again:
(enter it again)
Your identification has been saved in /home/drobbins/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
a4:e7:f2:39:a7:eb:fd:f8:39:f1:f1:7b:fe:48:a1:09 user@host
user@host# scp ~/.ssh/id_rsa.pub user@remote:
user@host# ssh user@remote
user@remote's password:
user@remote# cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
user@remote# exit
user@host#
[/code:1]
然后到 http://www.gentoo.org/proj/en/keychain/index.xml 下载最新版的 keychain,解压缩后安装到 /usr/bin/ 下(参看 README),修改 ~/.bash_profile 文件,添加下面几行:
[code:1]
# ssh-agent daemon
/usr/bin/keychain ~/.ssh/id_rsa
# redirect ~/.ssh-agent output to /dev/null to zap the annoying
# "Agent PID" message
source ~/.keychain/${HOSTNAME}-sh > /dev/null
[/code:1]
我用的版本是 keychain-2.6.8 不同版本的 keychain 需要改动上面不同的地方,该版本目前是生成 ~/.keychain/${HOSTNAME}-sh 这样的文件,以前的不是。
然后重新登陆就可以不用密码登陆 remote 了。