ssh 在一台机器上工作,但不能在另一台机器上工作

ssh works on one machine, but not another

我是 运行 在两台不同机器上的一个简单命令:

ssh -vvvT git@github.com

在一台机器上,这行得通。在另一台机器上,ssh 失败并显示以下消息:

debug1: Server accepts key: pkalg ssh-rsa blen 535
debug2: input_userauth_pk_ok: fp bd:5a:d9:2b:d0:36:1c:f1:dc:f8:83:05:17:b9:04:e0
debug3: sign_and_send_pubkey: RSA bd:5a:d9:2b:d0:36:1c:f1:dc:f8:83:05:17:b9:04:e0
debug1: key_parse_private2: missing begin marker
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug2: no passphrase given, try next key
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

我在两台机器上使用相同的私钥。私钥具有开始标记(即 -----BEGIN RSA PRIVATE KEY-----)。私钥是在没有密码的情况下生成的。 .ssh 目录的权限在两台机器 (700) 上是相同的。私钥文件的权限在两台机器 (600) 上是相同的。这是我的 .ssh/config:

的内容
Host github.com
    StrictHostKeyChecking no
    IdentityFile ~/keyfile

我完全不明白为什么输出显示 "missing begin marker",为什么它试图读取密码,当然还有为什么它完全失败了。有什么我应该尝试帮助诊断这个问题的吗?

密钥文件上没有标记表明它有密码。当 ssh 从文件中读取密钥时,它首先尝试在没有密码的情况下解释文件内容。如果它无法理解文件的内容,它会要求输入密码并再次尝试读取文件。您可以向 ssh 提供一个完整的废话文件,它会在放弃之前要求输入密码:

$ head -1500c < /dev/urandom > boguskey
$ chmod 600 boguskey
$ ssh -i boguskey localhost
Enter passphrase for key 'boguskey':

换句话说,如果 ssh 提示您输入密码,而您确信该文件不应该有密码,那么该文件一定有其他问题。例如,它可能被截断或损坏。