
我家裡有一台運行 Lion 的 Mac。我停用了密碼ssh登入;我只想使用公鑰。
我產生了私鑰/公鑰對,但現在我很困惑。我明天開始新工作,想從工作登入我的家用電腦。我看到的每個指南都說「首先使用密碼將(本地)公鑰複製到(伺服器)...」。
但是,如果我停用了密碼登錄,如何從新位置執行此操作?
如果我隨身攜帶其中一把鑰匙,是否可以透過某種方式從任何地方存取我的家用電腦?
我想,如果我只是將家庭機器公鑰複製到家庭機器“authorized_keys”中,然後使用筆記型電腦上的家庭機器私鑰,它就會起作用...
zmbp:~ dzg$ ssh -v 192.168.1.99
OpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to 192.168.1.99 [192.168.1.99] port 22.
debug1: Connection established.
debug1: identity file /Users/dzg/.ssh/identity type -1
debug1: identity file /Users/dzg/.ssh/id_rsa type 1
debug1: identity file /Users/dzg/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.6
debug1: match: OpenSSH_5.6 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 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: Host '192.168.1.99' is known and matches the RSA host key.
debug1: Found key in /Users/dzg/.ssh/known_hosts:6
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/dzg/.ssh/identity
debug1: Offering public key: /Users/dzg/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/dzg/.ssh/id_dsa
debug1: read PEM private key done: type DSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
答案1
在筆記型電腦上,除非您指示,否則 SSH 用戶端不會自動取得具有非預設名稱的金鑰。請注意,日誌顯示:
debug1:提供公鑰:/Users/dzg/.ssh/id_rsa
換句話說,它提供的預設金鑰是 ~/.ssh/id_rsa,而不是 ~/.ssh/home 金鑰。
您應該使用ssh -i ~/.ssh/home
明確指定您希望使用的密鑰。或者,您可以根據按鍵的實際類型將 home 鍵重新命名為筆記型電腦id_rsa
或在筆記型電腦上重新命名。id_dsa
此外,如果您遇到 SSH 金鑰驗證問題,請盡可能尋找伺服器端日誌:伺服器將記錄登入失敗的確切原因,但不會向客戶端透露,因為客戶端剛剛未能證明其身分。
據伺服器所知,未經身份驗證的客戶端可能是入侵者:沒有必要向他/她提供比絕對必要的更多線索。