ubuntu - 身份验证 localhost 失败,尽管有 ssh-keys

标签 ubuntu ssh continuous-integration github-actions nohup

我正在 CI 中设置我的虚拟机,以便我可以测试使用 ssh 的脚本。
我正在设置运行 Ubuntu 20.04.2 LTS 的虚拟机,如下所示:

sudo apt-get install openssh-server
ssh-keygen -t rsa -q -f "$HOME/.ssh/id_rsa" -N ""
cat "$HOME/.ssh/id_rsa.pub" >> "$HOME/.ssh/authorized_keys"
(根据文档,ssh-server 会自动启动,我使用 sudo systemctl status ssh 验证确实是这种情况)
调试我跑
ssh -v localhost "uname -r"
给予:
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /home/runner/.ssh/id_rsa type 0
debug1: identity file /home/runner/.ssh/id_rsa-cert type -1
debug1: identity file /home/runner/.ssh/id_dsa type -1
debug1: identity file /home/runner/.ssh/id_dsa-cert type -1
debug1: identity file /home/runner/.ssh/id_ecdsa type -1
debug1: identity file /home/runner/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/runner/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/runner/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/runner/.ssh/id_ed25519 type -1
debug1: identity file /home/runner/.ssh/id_ed25519-cert type -1
debug1: identity file /home/runner/.ssh/id_ed25519_sk type -1
debug1: identity file /home/runner/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/runner/.ssh/id_xmss type -1
debug1: identity file /home/runner/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:22 as 'runner'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:NFnWPH2boToKCX0yq1K33LY0K3EwK810f599LpwoXJI
debug1: read_passphrase: can't open /dev/tty: No such device or address
Host key verification failed.
为了完整性
cat /var/log/auth.log
给出:
Mar 10 06:13:08 fv-az189-848 php8.0: DIGEST-MD5 common mech free
Mar 10 06:13:09 fv-az189-848 php8.0: DIGEST-MD5 common mech free
Mar 10 06:13:09 fv-az189-848 php8.0: DIGEST-MD5 common mech free
Mar 10 06:13:52 fv-az189-848 sudo:   runner : TTY=unknown ; *** ; USER=root ; COMMAND=/usr/bin/apt-get install openssh-server
Mar 10 06:13:52 fv-az189-848 sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 10 06:13:55 fv-az189-848 sudo: pam_unix(sudo:session): session closed for user root
Mar 10 06:13:55 fv-az189-848 sudo:   runner : TTY=unknown ; *** ; USER=root ; COMMAND=/usr/bin/systemctl status ssh
Mar 10 06:13:55 fv-az189-848 sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 10 06:13:55 fv-az189-848 sudo: pam_unix(sudo:session): session closed for user root
Mar 10 06:13:55 fv-az189-848 sshd[1847]: Connection closed by ::1 port 54242 [preauth]
在我看来,ssh 可以找到 key ,但正在尝试读取我使用 -N "" 设置为空的密码。这里的选项:
ssh-keygen -t rsa -q -f "$HOME/.ssh/id_rsa" -N ""
因此,我不知道如何解决这个问题。我可以创建 /dev/tty但在我看来,ssh 甚至不应该寻找它。

最佳答案

我检查了你的设置,它对我有用。
但是在 Server host key 之后我的调试输出看起来有所不同

debug1: Server host key: ecdsa-sha2-nistp256 SHA256:NFnWPH2boToKCX0yq1K33LY0K3EwK810f599LpwoXJI
debug1: Host 'localhost' is known and matches the ECDSA host key.
debug1: Found key in /home/pi/.ssh/known_hosts:15
我假设 localhost不在您的 .ssh/known_host 中文件,因此 ssh想请您确认。
您可以尝试不检查就开始
ssh -v localhost "uname -r" -o StrictHostKeyChecking=no
但根本问题是您缺少 /dev/tty ,您当前的 tty 似乎以某种方式配置错误

关于ubuntu - 身份验证 localhost 失败,尽管有 ssh-keys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66561239/

相关文章:

visual-studio-2010 - 在没有团队基础服务器的情况下运行 Mstest.exe。

ubuntu - 启动 Vagrantbox 时出现 Openssl 3.0 错误

php - 如何在 ubuntu 后台运行多个 php 脚本?

python - 如何修复函数/符号 'pango_context_set_round_glyph_positions' 错误

linux - 使用powershell远程登录linux

amazon-web-services - 启用防火墙后无法通过 ssh 进入 AWS EC2

javascript - 关于将闭包编译器集成到构建流程的建议

ubuntu - spl-token : error while loading shared libraries: libssl. so.1.1:无法打开共享对象文件:没有这样的文件或目录

ssh - 无法使用 key 对登录 Amazon EC2 实例

azure - 如何在Azure DevOps Pipeline中设置和读取用户环境变量?