Ssh

mac ssh 在使用者模式下失敗 在 root 模式下成功獲取相同的私鑰

  • November 16, 2015

系統配置:

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 hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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 hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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 hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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.
root@198.18.144.158:~# exit   

根級配置更改:

我已將根級 ssh_config 更改為指向使用者級帳戶的私鑰,而不是預設的 rsa 密鑰。

我嘗試過

的:嘗試了使用者級別文件夾.sshinternal的不同權限,但不影響。

灣。嘗試過ssh-add,但看到看起來不錯的輸出。

C。在使用者級別和根級別檢查 known_hosts 並且看起來相同。

不知道是什麼導致了這個問題 - 因為在根級別我能夠驗證密鑰,而在使用者級別則不能這樣做。

歡迎任何幫助。

由於您沒有在 ssh 命令行上指定特定的使用者名:root當您使用時,您使用遠端系統上的使用者登錄,而當您不使用時,您使用的是sudo普通 OSX 使用者userxyz(或kimanjun其他使用者)登錄。

ssh root@198.18.144.158當您省略sudoor時嘗試 ssh -l root 198.18.144.158

如果您不想以 root 身份登錄,請改用正確的遠端登錄名並設置正確的 SSH 密鑰。

引用自:https://serverfault.com/questions/736713