即使设置了密钥,SSH也会要求输入密码

时间:2014-08-24 18:25:45

标签: ssh

我正在尝试通过this方法设置ssh密钥。

这是服务器上的起点

server:~/.ssh$ ls   
#shows empty

这是客户端的起点

client: ~/.ssh$ls #shows empty dir

在客户端,我运行

$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/me/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/me/.ssh/id_rsa.
Your public key has been saved in /Users/me/.ssh/id_rsa.pub.
The key fingerprint is:
26:25:e0:2f:90:d8:d9:fb:79:03:5d:99:a1:61:a9:dc me@machine
The key's randomart image is:
+--[ RSA 2048]----+
|    .   o..      |
| o = . ..o +     |
|. = o..oo +      |
|   . oo+E.       |
|    o + S        |
|     o =         |
|      o o        |
|       . .       |
|                 |
+-----------------+

$ ls
id_rsa      id_rsa.pub

到目前为止一切顺利。那我就跑

$ ssh-copy-id -p 3457 me@server #running on non standard port
The authenticity of host '[server]:3457 ([104.131.226.216]:3457)' can't be established.
RSA key fingerprint is 1c:52:db:19:22:b8:47:18:24:ad:07:2f:e5:d3:c4:8e.
Are you sure you want to continue connecting (yes/no)? yes
/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/local/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
me@server's password: 

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh -p '3457' 'me@server'"
and check to make sure that only the key(s) you wanted were added.

我运行ssh -p '3457' 'me@server'并看到~/.ssh/authorized_keys显示密钥匹配。我退出了,再次尝试sshing。但它仍然要求我输入密码 - 即使在服务器上运行sudo service ssh restart之后也是如此。我不确定我还能做什么。什么是下一个步骤?

2 个答案:

答案 0 :(得分:0)

确保您的会话中已加载该密钥

$ ssh-add

应打印〜/ .ssh / id_rsa

如果您收到错误消息" 无法与身份验证代理建立连接"然后执行

$ eval $(ssh-agent)

并重复ssh-add

前者应该足够了,但我也建议使用ssh配置文件。为此,编辑(或创建)包含内容的~/.ssh/config文件

Host server
    HostName 104.131.226.216
    User me
    Port 3457
    IdentityFile ~/.ssh/id_rsa

答案 1 :(得分:0)

authorized_keys文件644-rw-r--r--)的文件访问权限是什么?

(我会留下这个评论,但我没有足够的分数)