我想通过 SSH 连接到我的 CentOS 服务器,但显示权限被拒绝错误。
- 使用“ssh foo.bar.com”命令通过 RPI 连接到服务器 -> 失败(显示“权限被拒绝”)
- 使用“ssh-agent”、“ssh-add”和“ssh foo.bar.com”命令将 RPI 连接到服务器 -> 成功
- PC 使用“ssh foo.bar.com”命令连接到服务器 -> 成功
如何使用“ssh foo.bar.com”命令连接到服务器?
详情如下。
树莓派 -> 服务器
我尝试通过 SSH 从我的 Raspberry PI(Raspbian wheezy)连接到我的 CentOS 服务器。但显示权限被拒绝错误。我该如何连接到我的服务器?
d_komatsuda@raspberrypi ~ $ ssh -v foo.bar.com
然后我收到以下错误(摘录)。
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/d_komatsuda/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Trying private key: /home/d_komatsuda/.ssh/id_dsa
debug1: Trying private key: /home/d_komatsuda/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
权限如下:
d_komatsuda@raspberrypi /home $ ls -ld d_komatsuda
drwxr-xr-x 4 d_komatsuda d_komatsuda 4096 Oct 12 06:52 d_komatsuda
d_komatsuda@raspberrypi /home $ ls -ld d_komatsuda/.ssh
drwx------ 2 d_komatsuda d_komatsuda 4096 Oct 12 06:08 d_komatsuda/.ssh
d_komatsuda@raspberrypi /home $ ls -l d_komatsuda/.ssh
total 16
-rwx------ 1 d_komatsuda d_komatsuda 405 Oct 12 04:57 authorized_keys
-rw------- 1 d_komatsuda d_komatsuda 1743 May 25 18:39 id_rsa
-rwx------ 1 d_komatsuda d_komatsuda 405 Oct 12 04:55 id_rsa.pub
-rw-r--r-- 1 d_komatsuda d_komatsuda 1106 Oct 12 05:50 known_hosts
为什么没有显示“输入 .ssh/id_rsa 的密码:”?
此外,还有authorized_keys和id_rsa.pub,因为我想通过SSH从我的电脑访问。
Raspberry PI -> 服务器:使用 ssh-agent
我无法通过上述方式连接到我的服务器,但使用 ssh-agent,我可以连接。
d_komatsuda@raspberrypi ~ $ ssh-agent bash
d_komatsuda@raspberrypi ~ $ ssh-add .ssh/id_rsa
Enter passphrase for .ssh/id_rsa:
Identity added: .ssh/id_rsa (.ssh/id_rsa)
d_komatsuda@raspberrypi ~ $ ssh -v foo.bar.com
显示以下消息(摘录)。
debug1: Next authentication method: publickey
debug1: Offering RSA public key: .ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: Authentication succeeded (publickey).
Authenticated to foo.bar.com ([xxx.xxx.xxx.xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Last login: Sat Oct 12 20:49:30 2013 from xxxxxx.yyyyyy.jp
SAKURA Internet [Virtual Private Server SERVICE]
[d_komatsuda@www1447ui ~]$
为什么我可以使用 ssh-agent 连接到我的服务器,但没有 ssh-agent 就无法连接?
我的电脑(Cygwin)->服务器
从我的 Cygwin 控制台,我可以正确连接到我的服务器。
d_komatsuda@i7-975 ~
$ ssh -v foo.bar.com
然后我收到了以下消息(摘录)。
debug1: Next authentication method: publickey
debug1: Trying private key: /home/d_komatsuda/.ssh/id_rsa
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/home/d_komatsuda/.ssh/id_rsa':
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to foo.bar.com ([xxx.xxx.xxx.xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Last login: Sat Oct 12 17:03:13 2013 from xxxxxx.yyyyyy.jp
SAKURA Internet [Virtual Private Server SERVICE]
[d_komatsuda@www1447ui ~]$
请给我一些建议。
来自服务器端的日志
当我尝试从 RPi 连接到服务器并出现“权限被拒绝”错误时,我收到了以下日志(/var/log/secure)。
Oct 12 21:36:30 www1447ui sshd[16829]: debug1: Forked child 16857.
Oct 12 21:36:30 www1447ui sshd[16857]: Set /proc/self/oom_score_adj to 0
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: rexec start in 7 out 7 newsock 7 pipe 9 sock 10
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: inetd sockets after dupping: 3, 3
Oct 12 21:36:30 www1447ui sshd[16857]: Connection from yyy.yyy.yyy.yyy port 57716
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: Client protocol version 2.0; client software version OpenSSH_6.0p1 Debian-4
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: match: OpenSSH_6.0p1 Debian-4 pat OpenSSH*
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: Enabling compatibility mode for protocol 2.0
Oct 12 21:36:30 www1447ui sshd[16857]: debug1: Local version string SSH-2.0-OpenSSH_5.3
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: permanently_set_uid: 74/74
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: list_hostkey_types: ssh-rsa,ssh-dss
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEXINIT sent
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEXINIT received
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: kex: client->server aes128-ctr hmac-md5 none
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: kex: server->client aes128-ctr hmac-md5 none
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_NEWKEYS sent
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: expecting SSH2_MSG_NEWKEYS
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: SSH2_MSG_NEWKEYS received
Oct 12 21:36:30 www1447ui sshd[16858]: debug1: KEX done
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: userauth-request for user d_komatsuda service ssh-connection method none
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: attempt 0 failures 0
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: PAM: initializing for "d_komatsuda"
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: PAM: setting PAM_RHOST to "xxxxxx.yyyyyy.jp"
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: PAM: setting PAM_TTY to "ssh"
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: userauth-request for user d_komatsuda service ssh-connection method publickey
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: attempt 1 failures 0
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: test whether pkalg/pkblob are acceptable
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: temporarily_use_uid: 500/500 (e=0/0)
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: trying public key file /home/d_komatsuda/.ssh/authorized_keys
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: fd 4 clearing O_NONBLOCK
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: restore_uid: 0/0
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: temporarily_use_uid: 500/500 (e=0/0)
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: trying public key file /home/d_komatsuda/.ssh/authorized_keys2
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: restore_uid: 0/0
Oct 12 21:36:31 www1447ui sshd[16857]: Failed publickey for d_komatsuda from yyy.yyy.yyy.yyy port 57716 ssh2
Oct 12 21:36:31 www1447ui sshd[16858]: Connection closed by yyy.yyy.yyy.yyy
Oct 12 21:36:31 www1447ui sshd[16858]: debug1: do_cleanup
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: do_cleanup
Oct 12 21:36:31 www1447ui sshd[16857]: debug1: PAM: cleanup