我有一个 Ubuntu Server 和 OS X 和 Windows(Cygwin)客户端。
几天前,我能够在客户端上成功生成 RSA 密钥并将其复制到服务器:
ssh-copy-id <username>@<host>
而且我可以轻松地使用 SSH,而无需输入密码。
我创建了一个 cronjob,OS X 客户端会每晚备份 Documents 文件夹并发送包含输出的电子邮件。
最近,我在电子邮件中收到了此信息。
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at /SourceCache/rsync/rsync-45/rsync/io.c(453) [sender=2.6.9]
当我手动通过 SSH 进入服务器时,我意识到它再次提示输入密码。
我尝试重新启动服务器和客户端,生成新的 RSA 密钥并重新发送,更改服务器和客户端上 .ssh 文件夹的权限,
chmod 700 ~/.ssh
我尝试更改服务器主目录的权限
chmod go-w ~
尝试从不同的 OS X 机器执行相同的过程,将 SSH 密钥复制到服务器后,出现同样的错误,提示输入密码。
当我通过 SSH 访问服务器时输入 -v 时,我得到了以下信息(隐藏了服务器 IP、用户名和 RSA 密钥)
Andrews-MacBook-Pro:~ USER-NAME$ ssh -v Ubuntu-User@"Server-IP"
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to "Server-IP" ["Server-IP"] port 22.
debug1: Connection established.
debug1: identity file /Users/USER-NAME/.ssh/id_rsa type 1
debug1: identity file /Users/USER-NAME/.ssh/id_rsa-cert type -1
debug1: identity file /Users/USER-NAME/.ssh/id_dsa type -1
debug1: identity file /Users/USER-NAME/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA [RSA Key was Here]
debug1: Host '"Server-IP"' is known and matches the RSA host key.
debug1: Found key in /Users/USER-NAME/.ssh/known_hosts:3
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/USER-NAME/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/USER-NAME/.ssh/id_dsa
debug1: Next authentication method: password
Ubuntu-User@"Server-IP"'s password:
当我输入密码时,SSH 确实起作用,但我试图在午夜自动备份到服务器,并且不想不断输入密码。
我该如何修复此问题?
谢谢。
编辑:我查看了“/var/log/auth.log”,发现最上面的一行可能有帮助。下面显示了我输入密码然后打开日志的行。这些信息有帮助吗?
Mar 23 12:58:26 SERVER-USERNAME sshd[8799]: pam_ecryptfs: Passphrase file wrapped
Mar 23 12:58:28 SERVER-USERNAME sshd[8795]: Accepted password for SERVER-USERNAME from "CLIENT-IP" port 55224 ssh2
Mar 23 12:58:28 SERVER-USERNAME sshd[8795]: pam_unix(sshd:session): session opened for user SERVER-USERNAME by (uid=0)
Mar 23 12:58:28 SERVER-USERNAME systemd-logind[689]: New session 10 of user SERVER-USERNAME.
Mar 23 12:59:00 SERVER-USERNAME sudo: SERVER-USERNAME : TTY=pts/7 ; PWD=/home/SERVER-USERNAME ; USER=root ; COMMAND=/usr/bin/nano /var/log/auth.log
Mar 23 12:59:00 SERVER-USERNAME sudo: pam_unix(sudo:session): session opened for user root by SERVER-USERNAME(uid=0)
答案1
要确定问题的根源,请尝试在服务器上为 localhost 设置无密码登录。这样,您只需处理一台机器,即服务器。如果它确实有效,则问题是由客户端引起的;如果不行,您必须找出服务器本身的问题
答案2
我将一台显示器插入 Ubuntu 服务器(我相信它运行的是 Ubuntu 14 的桌面版),登录后看到一条消息,要求我创建密码。
我点击它并按下回车键(输入空白密码)。之后,我重新启动,无密码 SSH 登录似乎又可以正常工作了。
在我将其标记为完成之前,我会进行几天的测试以确保它不是其他东西。