How do I setup ssh from the host to the guest using qemu? I am able to use port redirection when I boot the VM without any special parameters, as follows:/usr/bin/qemu-system-x86_64 -hda ubuntu1204 -m 512 -redir tcp:7777::8001But when I try to boot using the following:/usr/bin/qemu-system-x86_64 \-m 1024 \-name vserialtest \-hda ubuntu1204 \-chardev socket,host=localhost,port=7777,server,nowait,id=port1-char \-device virtio-serial \-device virtserialport,id=port1,chardev=port1-char,name=org.fedoraproject.port.0 \-net user,hostfwd=tcp:7777::8001I get the following error and the VM does not boot:qemu-system-x86_64: -net user,hostfwd=tcp:7777::8001: invalid hostforwarding rule 'tcp:7777::8001'qemu-system-x86_64: -net user,hostfwd=tcp:7777::8001: Device 'user'could not be initializedPlease note that I am able to boot the VM without the -net parameterwithout any issues, however, I want to setup ssh from the host to theguest. ssh from guest to host works fine as expected.EditI have tried using-net user,hostfwd=tcp::7777-:8001as well as-net user,hostfwd=tcp::7777:8001but still the error persists and the VM does not boot.
ssh from host to guest using qemu
networking;ssh;qemu
I think that the error does not come from the -net statement, but from: -chardev socket,host=localhost,port=7777,server,nowait,id=port1-charThe statement uses already the port 7777. For the port forwarding, with -net user,hostfwd=tcp::7777-:8001it works fine when not setting up the virtio serial channel.If I understand right, you want to set up a virtio serial channel to communicate from the host to the VMusing a Unix Domain Socket? In this case, the following could do the job:/usr/bin/qemu-system-x86_64 \-m 1024 \-name vserialtest \-hda ubuntu1204 \-chardev socket,path=/tmp/port1,server,nowait,id=port1-char \-device virtio-serial \-device virtserialport,id=port1,chardev=port1-char,name=org.fedoraproject.port.0 \-net user,hostfwd=tcp::7777-:8001EDIT:An example of how to connect from the host using ssh to the VM:-net user,hostfwd=tcp::10022-:22-net nicThis hostforwarding maps the localhost (host) port 10022 to the port 22 on the VM. Once the VM was started like this, you can access it from the localhost as follows:ssh vmuser@localhost -p10022The -net nic command initializes a very basic virtual network interface card.