Skip to main content
  1. Posts/

Set up X11 Forwarding with Git for Windows (git-bash)

··453 words·3 mins·
Table of Contents

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 the following command instead:

service sshd restart

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 that 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 task bar 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 diagnose the X connection problems.

Trouble shotting

After logging 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 task bar, you will see that now it has 2 clients:

JD-PC:0.0 - 2 clients



How to Use Putty on Windows
··333 words·2 mins
Essential Knowledge about SSH
·964 words·5 mins
Display Image with Pillow inside Ubuntu on Windows
··268 words·2 mins