SSH免输入密码登录
场景:服务器A 采用ssh 登录服务器B,没有任何特殊设置情况下,采用ssh host.b 会出现提示Password: 让输入密码。如何可以不手工输入密码?
解决方案:
- 生成ssh公钥和私钥
- [[email protected] .ssh]$ ssh-keygen -t dsa
- Generating public/private dsa key pair.
- Enter file in which to save the key (/home/qingxu/.ssh/id_dsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /home/qingxu/.ssh/id_dsa.
- Your public key has been saved in /home/qingxu/.ssh/id_dsa.pub.
- The key fingerprint is:
- ba:43:5b:8e:80:50:5b:88:f1:01:99:1a:c8:73:68:ab [email protected]
将公钥copy到要登录的机器B上去,并在B的.ssh目录下,然后将id_dsa.pub的内容追加到authorized_keys文件中。
- cat id_dsa.pub >> authorized_keys
此时我们可以通过ssh host.b登录B服务器了,不会提醒Password了,不过。这个时候你仍然会看到这样的信息。
- [[email protected] ~]$ ssh host.b
- The authenticity of host 'host.b (xxxxxx)' can't be established.
- DSA key fingerprint is b9:d9:d6:69:c0:e5:bd:6d:c8:89:43:8a:a5:d6:ef:a4.
- Are you sure you want to continue connecting (yes/no)?
接着会出现以下信息:
- Enter passphrase for key '/home/qingxu/.ssh/id_dsa':
- 使用ssh-agent和ssh-add管理密钥
ssh-agent是用于管理密钥,ssh-add用于将密钥加入到ssh-agent中,SSH可以和ssh-agent通信获取密钥,这样就不需要用户手工输入密码了。
eval `ssh-agent` ssh-add Enter passphrase for /home/qingxu/.ssh/id_dsa:
不过由于每次登录都需要设置一次,所以最好将命令放到~/.bash_profile中。
另外,可以采用keychain来处理这一步,参考:
相关推荐
projava 2020-11-14
WanKaShing 2020-11-12
airfish000 2020-09-11
tryfind 2020-09-14
yegen00 2020-09-10
kkaazz 2020-09-03
风语者 2020-09-02
BraveWangDev 2020-08-19
lichuanlong00 2020-08-15
gsl 2020-08-15
pandaphinex 2020-08-09
yhuihon 2020-08-09
CheNorton 2020-08-02
xiangqiao 2020-07-28
hpujsj 2020-07-26
hpujsj 2020-07-26
sshong 2020-07-19
BraveWangDev 2020-07-19
annan 2020-07-18