我家里有一台运行 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
来明确指定要使用的密钥。或者,您可以将主密钥重命名为id_rsa
或id_dsa
,具体取决于密钥的实际类型。
此外,如果您遇到 SSH 密钥验证问题,请尽可能找到服务器端日志:服务器将记录登录失败的确切原因,但不会向客户端透露,因为客户端只是无法证明其身份。
据服务器所知,未经身份验证的客户端可能是一个入侵者:没有必要向他/她提供比绝对必要的更多的线索。