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
/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
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
After starting the X server, we need to configure the ssh.
First, open git-bash, change directory to
$HOME and create
write following options in the
Save the file and restart git-bash.
Second, connect to your remote server using the following command:
ssh -X -v <user>@<server_addresss>
-v is used to diagnose the X connection problems.
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>
xclock program with
xclock &. It should works fine.
We can run multiple GUI applications, for example
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
License CC BY-NC-ND 4.0