How to X session forwarding over SSH

3

SSH allows secure (encrypted and authenticated) connections between two hosts. These connections include terminal sessions, file transfers, TCP port forwarding, as well as X window forwarding which I will be covering here. X forwarding is a form of tunneling that allows you to run a GUI application on a remote machine but let you view and interact with it on your local machine.

To try this out you will need both X and SSH installed on your local and remote machines. Make sure that you are able to log into the the remote machine over SSH before you continue.

Simple SSH command, ensure that this works before continuing. You may have to enter a password for the user before it will allow you access.

The next step is to add the ‘-X‘ option. This will turn on X forwarding and allow you to remotely run X programs. In this case we will run xclock.

You should see the xclock window appear on your screen. You can interact with it like any other local application window. Close it when you are done.

If you have a slower connection you can turn on compression by adding the ‘-C‘ option to the command above. This will compress all data communications with the gzip algorithm.

If you are experiencing any problems turn on verbose output with the ‘-v‘ option. This will give you a lot more output and tell you what is going on underneath.

If you are still having issues look in the ssh configuration file here/etc/ssh/ssh_config, and make sure that you don’t have X forwarding settings disabled.

Share.
  • Ryan

    Great information, Thanks.

  • http://www.dr-jan.com/tips Jan Ives

    You can also login and then run X programs as separate steps:

    ssh -X user@remotehost

    remotehost> xlogo
    remotehost> xclock

    If X forwarding doesn’t work, you may need to check it hasn’t been disabled on the remote host – look in /etc/ssh/sshd_config on the remote host.

    You can also daisy-chain hosts if you need to access one server via another, for example:

    ssh -X user@remotehost
    remotehost> ssh -X user2@remotehost2
    remotehost2> xlogo

    If you want to default ssh to always use ‘-X’ either set up an alias or create a file ~/.ssh/config and add this line to it:

    ForwardX11=yes

  • alvaro cervantes

    How can I send an X application to another computer? I want to push a button and send the login screen from my desktop to a tablet so in my tablet I can login and use the application (that is running on the desktop). Is there any concerns with fonts, display or screen resolution?
    Thanks,
    Al Cervantes