0%

How to Run Remote X Applications in Bash on Windows

ssh to a remote server and run programs inside a terminal is not a big deal for major operating systems. However if the remote program requires graphics display, it will be a little bit tricky. macOS does have a powerful terminal that can automatically create an X window for the remote application. Windows could do that too, with some sort of hacking. Thanks to the great bash on windows, the effort to run remote X applications is now minimized. The detailed steps are shown below.

First, go to source forge website and download Xming, which serves as an X display manager for windows system. After installation, open the XLaunch application to start its service. You may want to choose "Multiple windows" and "Start no client" in the configuration. After finishing this process, Xming should be in your system tray and ready to serve X applications.

Second, open bash.exe, insert the following line at the end of .bashrc file. This will add a variable called $DISPLAY to the environment.

1
export DISPLAY='localhost:0.0'

You can now type source .bashrc command under your home folder to apply the change immediately.

Finally, execute the remote X application inside bash terminal with ssh X11 forwarding:

1
ssh -X username@server.addr ABSOLUTE_PATH_TO_X_APPLICATION

Do you see the pop-up window? It is done!

This approach works pretty well with OpenGL applications. The main drawback is that we need to create an ssh connection for each X application, rather than keep one connection and create new windows. Compared with either virtual machine or some fancy settings, this simple approach should be a better solution in most situations.