Administering a QEMU guest with OpenSSH


So you’ve just installed a QEMU guest and you realize that all you reallyneed to administer it is SSH; SDL and VNC are overkill. Since AFAICS KVM’s default networking configuration prevents you from initiating host->guest TCP/IP connections, you’ll want to take advantage of SSH’s reverse tunneling (-R) capability.

After installing installing sshd on the guest and host, execute this on the guest:

ssh -R 9898:127.0.0.1:22 your_username_on_host@10.0.2.2

What this command does is…

  1. Opens an ssh connection from the guest to the host. 10.0.2.2 is the address of host as presented to the guest via the private VLAN.
  2. Once the connection is open, SSH begins listening on the host’s loopback adapter on port 9898 for connections which it will forward to port 22 on the guest.

Now, you can simply run this on the host to open an SSH connection to the guest:

ssh -p 9898 your_username_on_guest@localhost

This technique of course can be used to make any guest-based services available to the host. It’s not limited to the virtualization realm either.
Enjoy!

Update: QEMU’s `-redir` option is a simpler way to achieve the above.


Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!