我在通过 SSH 进行主机-来宾网络时遇到了一些问题。我在这里查看了许多问题以及 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 时不一致:
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)
答案1
我能够找到问题;这是我的 QEMU 命令的问题。启动 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,hostfwd=tcp::2222-:22 \
-nographic
然后我可以从主机进行 SSH:
<user>@<host>:~$ ssh <host>@localhost -p 2222
<user>@localhost's password:
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 5.2.0-050200-generic aarch64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Last login: Thu Dec 12 14:31:28 2019
<user>@<guest>:~$
答案2
您有一个/etc/hosts.deny
阻止ssh
登录的条目。
例如,这将拒绝来自所有远程系统的所有服务的入站连接尝试:
ALL : ALL
在我的 Debian 系统上,该文件包含拒绝登录的/var/log/auth.log
原因。ssh
你的客人身上也会有类似的东西。与我在此处显示的示例条目相对应的条目hosts.deny
看起来像这样
Dec 11 22:54:40 vmguest sshd[30741]: refused connect from 192.168.1.2 (192.168.1.2)
答案3
服务是否sshd
在您的来宾操作系统上运行?qemu
只需将您的包裹从 转发localhost:5555
到,如果您的来宾操作系统上guesthost:22
没有侦听端口 22 的服务,那么它将是。sshd
Connection reset by peer