![为什么我无法免密码连接到本地 ssh 服务器?](https://linux22.com/image/147545/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E6%97%A0%E6%B3%95%E5%85%8D%E5%AF%86%E7%A0%81%E8%BF%9E%E6%8E%A5%E5%88%B0%E6%9C%AC%E5%9C%B0%20ssh%20%E6%9C%8D%E5%8A%A1%E5%99%A8%EF%BC%9F.png)
我尝试使 ssh 连接到本地 ssh 服务器无需密码:
$ ls ~/.ssh
config id_dsa id_dsa.pub id_rsa id_rsa.pub known_hosts known_hosts.old
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-VYbFIb5qW0vi/agent.28080; export SSH_AUTH_SOCK;
SSH_AGENT_PID=28085; export SSH_AGENT_PID;
echo Agent pid 28085;
$ ssh-add ~/.ssh/id_rsa
Identity added: /home/t/.ssh/id_rsa (/home/t/.ssh/id_rsa)
但为什么我仍然需要提供密码?谢谢。
$ ssh t@localhost
t@localhost's password:
$ ssh -i ~/.ssh/id_rsa t@localhost
t@localhost's password:
答案1
目标主机必须有一个$HOME/.ssh/authorized_keys
文件,其中包含被授予访问权限的人员的公钥。所以,就你而言,你会这样做
$ cp $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
$ chmod go= $HOME/.ssh/authorized_keys
这些命令中的后者使除$USER
.