当我从 Mac 12.6 系统 ssh 进入 Ubuntu 20.04.1 系统时,每次都会提示我输入密钥密码,但不知道如何摆脱提示。下面是 Ubuntu 系统的输出,我在调试模式下手动运行 sshd,但我不太熟悉它显示的内容,无法确定问题所在。
root@dell:/etc/ssh# mkdir /var/run/sshd; chmod 0755 /var/run/sshd; /usr/sbin/sshd -d
debug1: sshd version OpenSSH_8.2, OpenSSL 1.1.1f 31 Mar 2020
debug1: private host key #0: ssh-rsa SHA256:Qi+QfQXlZMNzXx2rc4lTr8Sa2n8NzGShKKlFHlgIJT4
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:XqYwNkxd/ELRRSp2tzfOAst5H+xwJUjZF95BfkCLIYk
debug1: private host key #2: ssh-ed25519 SHA256:wIWr6ju0DTop8DTREi+uJPxvHJvT+eJxXFq/jgMaJFU
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
debug1: Server will not fork when running in debugging mode.
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: sshd version OpenSSH_8.2, OpenSSL 1.1.1f 31 Mar 2020
debug1: private host key #0: ssh-rsa SHA256:Qi+QfQXlZMNzXx2rc4lTr8Sa2n8NzGShKKlFHlgIJT4
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:XqYwNkxd/ELRRSp2tzfOAst5H+xwJUjZF95BfkCLIYk
debug1: private host key #2: ssh-ed25519 SHA256:wIWr6ju0DTop8DTREi+uJPxvHJvT+eJxXFq/jgMaJFU
debug1: inetd sockets after dupping: 3, 3
Connection from 192.168.1.9 port 63434 on 192.168.1.30 port 22 rdomain ""
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.6
debug1: match: OpenSSH_8.6 pat OpenSSH* compat 0x04000000
debug1: permanently_set_uid: 126/65534 [preauth]
debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: SSH2_MSG_KEXINIT received [preauth]
debug1: kex: algorithm: curve25519-sha256 [preauth]
debug1: kex: host key algorithm: ssh-ed25519 [preauth]
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none [preauth]
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none [preauth]
debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth]
debug1: rekey out after 134217728 blocks [preauth]
debug1: SSH2_MSG_NEWKEYS sent [preauth]
debug1: Sending SSH2_MSG_EXT_INFO [preauth]
debug1: expecting SSH2_MSG_NEWKEYS [preauth]
debug1: SSH2_MSG_NEWKEYS received [preauth]
debug1: rekey in after 134217728 blocks [preauth]
debug1: KEX done [preauth]
debug1: userauth-request for user mth service ssh-connection method none [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: PAM: initializing for "mth"
debug1: PAM: setting PAM_RHOST to "192.168.1.9"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: userauth-request for user mth service ssh-connection method publickey [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: userauth_pubkey: test pkalg rsa-sha2-512 pkblob RSA SHA256:OZm4uD0KuWx6Z494aecU2mD4GmWpmujCXaZkE+D2icY [preauth]
debug1: temporarily_use_uid: 1000/1000 (e=0/0)
debug1: trying public key file /home/mth/.ssh/authorized_keys
debug1: fd 4 clearing O_NONBLOCK
debug1: /home/mth/.ssh/authorized_keys:1: matching key found: RSA SHA256:OZm4uD0KuWx6Z494aecU2mD4GmWpmujCXaZkE+D2icY
debug1: /home/mth/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Accepted key RSA SHA256:OZm4uD0KuWx6Z494aecU2mD4GmWpmujCXaZkE+D2icY found at /home/mth/.ssh/authorized_keys:1
debug1: restore_uid: 0/0
Postponed publickey for mth from 192.168.1.9 port 63434 ssh2 [preauth]
我将不胜感激任何提示。谢谢。
答案1
这本身并不是一个真正的问题 - Mac 系统上的私钥受密码保护,并且必须先解锁该私钥,然后才能将其呈现给 Ubuntu 系统进行身份验证。
您有两个选择 - 第一个是使用私钥ssh-agent
并将ssh-add
其解锁一次到内存代理中,使用该解锁的代理向 Ubuntu 系统显示您的身份。这是“更好”的选项,因为它使身份受到密码短语的保护。我在引号中加上了更好的内容,因为我觉得这更多的是关于这个选项是否更好的意见,因为它可以保证密钥的安全,或者更糟,因为这意味着每次启动系统时都要处理代理的额外步骤。
$ eval `ssh-agent`
Agent pid 123456
$ ssh-add
Enter passphrase for /home/user/.ssh/id_rsa:
每次运行命令时,上面的代理 PID 都会改变eval
。身份文件将是您存储私有身份文件的位置,并且每次运行命令时都会相同eval
。
第二个选项是创建一个不带密码的新 SSH 密钥对,将新的公钥分发到您的 Ubuntu 系统,并使用不受保护的身份。
编辑:您还可以使用ssh-keygen -p
从现有密钥对中删除密码,如 dave_thompson_085 在评论中指出的那样。