0

I've been having some problems with Host-Guest networking via SSH. I've looked through many questions here as well as the Networking Documentation for QEMU (https://wiki.qemu.org/Documentation/Networking#How_to_get_SSH_access_to_a_guest), but have not been able to find an answer.

My guest QEMU instance is able to SSH into the host machine as normal. However, when I try to SSH into the QEMU instance from the host machine I get a ssh_exchange_identification: read: Connection reset by peer error.

Here is the command I use to boot 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

Once QEMU is booted, I try to SSH using the following command and get this output:

<*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

Any help with this is greatly appreciated!

Edit:

Both machines are running Ubuntu 18.04.

Host:

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

Guest:

Linux qemu-trace 5.2.0-050200-generic #201907072331 SMP Sun Jul 7 23:48:00 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux

Guest is running sshd,

ps -ef | grep '[s]shd'
root 616 1 0 Dec11 ? 00:00:00 /usr/sbin/sshd -D

This is an excerpt of /var/log/auth.log on the Guest if it helps. I'm reading an authentication failure, but unsure what that means as the timestamps don't align with when my host was 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)
  • Are you trying via passwords, or do you want to use public/private key pairs? Have you tried using the guest's hostname instead of port forwarding? – ajgringo619 Dec 11 '19 at 22:25
  • Just trying via passwords right now. I want to get it working before I do any public/private key stuff. Also trying to use the guest's hostname results in a: ssh: Could not resolve hostname qemu-lab1: Name or service not known error. – Tex4066 Dec 11 '19 at 22:34
  • You'll need to add the hosts entries to /etc/hosts. When I setup ssh on my guests, all I did (besides the default install) was disable password authentication. Are your guests on the default NAT network? If so, you should be able to login directly, without using port forwarding. – ajgringo619 Dec 11 '19 at 23:13
  • Need information: Host OS? Guest OS? pings from host to OS and OS to Host? guest network is NAT/Bridge? & configuration? – Chronos Dec 12 '19 at 11:04
  • 1
    <user>@<guest>:~$ ps -ef | grep sshd yeilds: root 616 1 0 Dec11 ? 00:00:00 /usr/sbin/sshd -D – Tex4066 Dec 12 '19 at 22:23
1

I was able to find the issue; it was a problem with my QEMU command. New command to boot 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

And then I can SSH from the Host:

<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>:~$
0

You've got an entry in /etc/hosts.deny that prevents the ssh login.

For example, this will deny inbound connection attempts for all services from all remote systems:

ALL : ALL

On my Debian system, the file /var/log/auth.log contains reasons for ssh having refused a login. There will be something similar on your guest. An entry corresponding to the hosts.deny example entry I've shown here looks something like this

Dec 11 22:54:40 vmguest sshd[30741]: refused connect from 192.168.1.2 (192.168.1.2)
  • Hello. Unfortunately, my /etc/hosts.deny file is empty. I have also changed the /etc/hosts.allow to include: ALL : ALL but neither seemed to work. I also do not see a refusal occur in the /var/log/auth.log file – Tex4066 Dec 12 '19 at 2:36
  • @Tex4066 what's your guest OS? (uname -a added to your question would be ideal) – roaima Dec 12 '19 at 8:25
  • I've edited my question with more information. – Tex4066 Dec 12 '19 at 17:13
0

Is sshd service running on your guest OS? qemu just forward your package from localhost:5555 to guesthost:22, if there is no sshd service listening on port 22 on your guest os, it will be Connection reset by peer.

  • Edited my question. sshd is running on my guest OS – Tex4066 Dec 12 '19 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.