As I have posted earlier, Cmder is a better option if you use Windows command line frequently. The full installation of Cmder comes with Git for Windows, which is handy to provide a Linux-like environment. In this post, I will write about how to use Git for Windows to connect to a remote CentOS server and set up X11 forwarding to use the GUI applications on that server.

Enable X11 forwarding on your CentOS server

First, you need to make sure that your server support X11 forwarding. Edit the file /etc/sshd_config and use the following settings:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no

If you are using CentOS 7, you should use

systemctl restart sshd.service

to restart the sshd service. If you are on CentOS 6, you should use

service sshd restart

instead.

Install X server program on Windows

In order to use X11 forwarding, you also need to install a X server on your Windows computer. You can choose to install xming or vcxsrv. Vcxsrv is better since it is updated frequently and is free, while latest version of xming requires a license. There is a good post which introduces vcxsrv.

In this post, we stick to vcxsrv. Install the application, and you will see two program: xlaunch and vcxsrv. Xlaunch is used to configure the X server and vcxsrv is used to start the server. Open xlaunch and use the default settings. Then start vcxsrv. The program will run in the background. Go to the taskbar and point to program, you will see information like the following:

JD-PC:0.0 - 0 clients

Configure ssh

After starting the X server, we need to configure the ssh.

First, open git-bash, change directory to $HOME and create .bash_profile, write following options in the .bash_profile

export DISPLAY=localhost:0.0

Save the file and restart git-bash.

Second, connect to your remote server using the following command:

ssh -X -v <user>@<server_addresss>

The option -v is used to diagonose the X connection problems.

Trouble shotting

After logining into your server, you may notice a warning message during login:

Warning: untrusted X11 forwarding setup failed: xauth key data not generated

If you try to start a GUI program, e.g., xclock, you may see an error message:

Error: Can’t open display:

If that is the case, close the session and try to use the following command to connect to your server instead:

ssh -Y -v <user>@<server_addresss>

Rerun the xclock program with xclock &. It should works fine.

We can run multiple GUI applications, for example xclock &, xeyes &. If you point to vcxsrv icon in the taskbar, you will see that now it has 2 clients:

JD-PC:0.0 - 2 clients


References