Read more

SSH: X-Forwarding

Tobias Kraze
July 27, 2018Software engineer at makandra GmbH

If you need to run a program on a remote machine (e.g. to your office PC) with a graphical UI (and you trust the remote machine), you can use SSH X-Forwarding. I sometimes use this to connect to a virtual machine installed on my work PC from my home office.

Forwarding X over SSH

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

To use X forwarding, when connecting to the remote machine, and add -X to the ssh call. Now, when you start a program with a UI (e.g. virtualbox) in that SSH session, a window will open on your local machine. It will not be particularly snappy, but on a decent connection it will be usable.

Note: This allows the remote machine to gain access to your X session, which is a security risk. Only use -X if you trust the remote machine a 100%. Do not make it a default in your SSH config.

Configuring sshd

The remote machine may not be configured to forward X by default. In that case, when connecting via ssh -X, you will get a warning:

X11 forwarding request failed on channel 0

To fix that, you need to enable X forwarding on the target machine:

  1. ssh remote-machine
  2. sudo vim /etc/ssh/sshd_config
  3. Set X11Forwarding yes and save
  4. sudo service sshd reload (existing connections will not be terminated)
Posted by Tobias Kraze to makandra dev (2018-07-27 19:09)