我在通过 SSH 进行 Host-Guest 网络时遇到了一些问题。我在这里查看了许多问题以及 QEMU 的网络文档(https://wiki.qemu.org/Documentation/Networking#How_to_get_SSH_access_to_a_guest),但未能找到答案。
我的来宾 QEMU 实例能够像往常一样通过 SSH 连接到主机。但是,当我尝试从主机通过 SSH 连接到 QEMU 实例时出现ssh_exchange_identification: read: Connection reset by peer
错误。
这是我用来启动 QEMU 的命令:
qemu-system-aarch64 -M virt -m 32768 -cpu cortex-a72 \
-kernel $VMLINUZ \
-initrd $INITRD \
-append 'root=/dev/vda2' \
-drive if=none,file=$COW,format=qcow2,id=hd \
-device virtio-blk-pci,drive=hd \
-netdev user,id=mynet \
-device virtio-net-pci,netdev=mynet \
-nographic \
-device e1000,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:22
启动 QEMU 后,我尝试使用以下命令 SSH 并获得以下输出:
<*user*>@<*hostname*>:~$ ssh localhost -p 5555 -vvv
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "localhost" port 5555
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 5555.
debug1: Connection established.
debug1: identity file /home/<*user*>/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/<*user*>/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<*user*>/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<*user*>/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<*user*>/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<*user*>/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<*user*>/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<*user*>/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
ssh_exchange_identification: read: Connection reset by peer
非常感谢您对此的任何帮助!
编辑:
两台机器都运行 Ubuntu 18.04。
主持人:
Linux trace5 5.0.0-37-generic #40~18.04.1-Ubuntu SMP Thu Nov 14 12:06:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
来宾:
Linux qemu-trace 5.2.0-050200-generic #201907072331 SMP Sun Jul 7 23:48:00 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux
来宾正在运行sshd
,
ps -ef | grep '[s]shd'
root 616 1 0 Dec11 ? 00:00:00 /usr/sbin/sshd -D
/var/log/auth.log
如果有帮助,这是对客人的摘录。我正在阅读身份验证失败,但不确定这意味着什么,因为时间戳与我的主机 ssh-ing 的时间不一致:
Dec 11 18:43:17 qemu-trace sshd[1547]: Server listening on 0.0.0.0 port 22.
Dec 11 18:43:17 qemu-trace sshd[1547]: Server listening on :: port 22.
Dec 11 18:43:17 qemu-trace sudo: pam_unix(sudo:session): session closed for user root
Dec 11 18:45:30 qemu-trace systemd-logind[610]: New seat seat0.
Dec 11 18:45:33 qemu-trace sshd[617]: Server listening on 0.0.0.0 port 22.
Dec 11 18:45:33 qemu-trace sshd[617]: Server listening on :: port 22.
Dec 11 18:46:18 qemu-trace login[620]: pam_unix(login:session): session opened for user trace by LOGIN(uid=0)
Dec 11 18:46:19 qemu-trace systemd-logind[610]: New session 1 of user trace.
Dec 11 18:46:19 qemu-trace systemd: pam_unix(systemd-user:session): session opened for user trace by (uid=0)
Dec 11 19:17:01 qemu-trace CRON[675]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 11 19:17:02 qemu-trace CRON[675]: pam_unix(cron:session): session closed for user root
Dec 11 19:20:13 qemu-trace systemd-logind[605]: New seat seat0.
Dec 11 19:20:17 qemu-trace sshd[616]: Server listening on 0.0.0.0 port 22.
Dec 11 19:20:17 qemu-trace sshd[616]: Server listening on :: port 22.
Dec 11 19:22:33 qemu-trace login[621]: pam_unix(login:auth): check pass; user unknown
Dec 11 19:22:33 qemu-trace login[621]: pam_unix(login:auth): authentication failure; logname=LOGIN uid=0 euid=0 tty=/dev/ttyAMA0 ruser= rhost=
Dec 11 19:22:37 qemu-trace login[621]: FAILED LOGIN (1) on '/dev/ttyAMA0' FOR 'UNKNOWN', Authentication failure
Dec 11 19:22:49 qemu-trace login[621]: pam_unix(login:session): session opened for user trace by LOGIN(uid=0)
Dec 11 19:22:49 qemu-trace systemd-logind[605]: New session 1 of user trace.
Dec 11 19:22:50 qemu-trace systemd: pam_unix(systemd-user:session): session opened for user trace by (uid=0)
我能够找到问题;这是我的 QEMU 命令的问题。启动 QEMU 的新命令:
然后我可以从主机 SSH:
您有一个条目
/etc/hosts.deny
阻止ssh
登录。例如,这将拒绝来自所有远程系统的所有服务的入站连接尝试:
在我的 Debian 系统上,该文件
/var/log/auth.log
包含ssh
拒绝登录的原因。你的客人也会有类似的东西。hosts.deny
与我在此处显示的示例条目对应的条目看起来像这样服务是否
sshd
在您的客户操作系统上运行?qemu
只需将您的包从 转发localhost:5555
到guesthost:22
,如果您的来宾操作系统上的端口 22 上没有sshd
服务侦听,它将是Connection reset by peer
.