mac ssh 在用户模式下失败,在根模式下使用相同的私钥成功

mac ssh 在用户模式下失败,在根模式下使用相同的私钥成功

系统配置:

MAC Version : 10.10.5  
    uname -a
    Darwin xxxxx-xxxx 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep  1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64

问题:
无法使用 SSH 私钥以用户模式连接到服务器。但是,使用相同 SSH 密钥(与用户位于同一位置)的相同命令可以很好地进行 root 身份验证。

失败输出日志(用户级命令):

> ssh -v -2A 198.18.144.158
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/userxyz/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to 198.18.144.158 [198.18.144.158] port 22.
debug1: Connection established.
debug1: identity file /Users/userxyz/.ssh/internal/2009-01-01.ppk type -1
debug1: identity file /Users/userxyz/.ssh/internal/2009-01-01.ppk-cert type -1
debug1: identity file /Users/userxyz/.ssh/internal/2009-01-01.ppk type -1
debug1: identity file /Users/userxyz/.ssh/internal/2009-01-01.ppk-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 Server-VIII-hpn14v2
debug1: no match: Server-VIII-hpn14v2
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: DSA ee:33:bd:ac:7b:6e:bd:0b:60:6e:49:20:56:cb:00:d3
debug1: Host '198.18.144.158' is known and matches the DSA host key.
debug1: Found key in /Users/userxyz/.ssh/known_hosts:1
debug1: ssh_dss_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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/userxyz/.ssh/internal/2009-01-01.ppk
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/kimanjun/.ssh/internal/2015-11-16.ppk
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: No more authentication methods to try.
Permission denied (publickey).

用户级别配置变更

pwd
/Users/userxyz/.ssh
> cat config 
IdentityFile ~/.ssh/internal/2009-01-01.ppk
>

成功输出日志(根级别命令):

sudo  ssh -v -2A 198.18.144.158 
Password:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to 198.18.144.158 [198.18.144.158] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /Users/userxyz/.ssh/internal/2009-01-01.ppk type -1
debug1: identity file /Users/userxyz/.ssh/internal/2009-01-01.ppk-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 Server-VIII-hpn14v2
debug1: no match: Server-VIII-hpn14v2
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: DSA ee:33:bd:ac:7b:6e:bd:0b:60:6e:49:20:56:cb:00:d3
debug1: Host '198.18.144.158' is known and matches the DSA host key.
debug1: Found key in /var/root/.ssh/known_hosts:1
debug1: ssh_dss_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
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/userxyz/.ssh/internal/2009-01-01.ppk
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to 198.18.144.158 ([198.18.144.158]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: SSH2_MSG_KEXINIT received
debug1: SSH2_MSG_KEXINIT sent
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: DSA ee:33:bd:ac:7b:6e:bd:0b:60:6e:49:20:56:cb:00:d3
debug1: Host '198.18.144.158' is known and matches the DSA host key.
debug1: Found key in /var/root/.ssh/known_hosts:1
debug1: ssh_dss_verify: signature correct
debug1: set_newkeys: rekeying
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: set_newkeys: rekeying
debug1: SSH2_MSG_NEWKEYS received
debug1: Requesting authentication agent forwarding.
This is a private system.  No unauthorized use is permitted; if you are
not an authorized user, please log off now.
[email protected]:~# exit   

根级别配置更改:
我已将根级别 ssh_config 更改为指向用户级别帐户的私钥,而不是默认的 rsa 密钥。

我已尝试过:
a. 尝试了用户级别文件夹的不同权限.sshinternal但没有影响。b
. 尝试了,ssh-add但看到输出看起来没问题。c
. 检查了用户级别和根级别的 known_hosts,看起来相同。

不确定是什么导致了这个问题——因为在根级别我能够验证密钥,但在用户级别却不能这样做。

欢迎任何帮助。

答案1

由于您没有在 ssh 命令行上指定特定的用户名:root当您使用时,您将以远程系统上的用户身份登录,而当您不使用时,您将以sudo普通 OSX 用户userxyz(或其他)身份登录。kimanjun

当您省略或时尝试 。ssh [email protected]sudossh -l root 198.18.144.158

如果您不想以 root 身份登录,请使用正确的远程登录名并设置正确的 SSH 密钥。

相关内容