我尝试使 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
.