Skip to content

Instantly share code, notes, and snippets.

@DestinyOne
Last active April 13, 2025 10:28
Show Gist options
  • Save DestinyOne/f236f71b9cdecd349507dfe90ebae776 to your computer and use it in GitHub Desktop.
Save DestinyOne/f236f71b9cdecd349507dfe90ebae776 to your computer and use it in GitHub Desktop.
Letting ubuntu bash on Windows 10 run 'ssh -X' to get a GUI environment in a remote server

Letting Ubuntu bash on Windows 10 run 'ssh -X' to get a GUI environment on a remote server

  • First

Install all the following. On Window, install Xming. On Ubuntu bash, use sudo apt install to install ssh xauth xorg.

sudo apt install ssh xauth xorg
  • Second

Go to the folder contains ssh_config file, mine is /etc/ssh.

  • Third

Edit ssh_config as administrator(USE sudo). Inside ssh_config, remove the hash # in the lines ForwardAgent, ForwardX11, ForwardX11Trusted, and set the corresponding arguments to yes.

# /etc/ssh/ssh_config

Host *
    ForwardAgent yes
    ForwardX11 yes
    ForwardX11Trusted yes
  • Forth

In ssh_config file, remove the front hash # before Port 22 and Protocol 2, and also append a new line at the end of the file to state the xauth file location, XauthLocaion /usr/bin/xauth, remember write your own path of xauth file.

# /etc/ssh/ssh_config

#   IdentifyFile ...
    Port 22
    Protocol 2
#   Cipher 3des
#   ...
#   ...
    ...
    ...
    GSSAPIDelegateCredentials no
    XauthLocaion /usr/bin/xauth
  • Fifth

Now since we are done editing ssh_config file, save it when we leave the editor. Now go to folder ~ or $HOME, append export DISPLAY=localhost:0 to your .bashrc file and save it.

# ~/.bashrc
...
...
export DISPLAY=localhost:0
  • Last

We are almost done. Restart your bash shell, open your Xming program and use ssh -X yourusername@yourhost. Then enjoy the GUI environment.

ssh -X yourusername@yourhost
@akay
Copy link

akay commented Jan 29, 2020

Can I ask where do I edit the ssh_config? On the server or local

ssh_config is for settings related to the client, so, local.

@Kelly510
Copy link

Kelly510 commented May 6, 2021

I was trying to use cv2.imshow after these steps to test the GUI, but it showed error like 'connect localhost port 6000: Connection refused Unable to init server: Could not connect: Connection'. I searched a solution for this: add 'xhost +' in the end of ~/.bashrc. But finally it showed another 'xhost: unable to open display "localhost:0"'. Can I ask where may be the problem?

@DestinyOne
Copy link
Author

I was trying to use cv2.imshow after these steps to test the GUI, but it showed error like 'connect localhost port 6000: Connection refused Unable to init server: Could not connect: Connection'. I searched a solution for this: add 'xhost +' in the end of ~/.bashrc. But finally it showed another 'xhost: unable to open display "localhost:0"'. Can I ask where may be the problem?

Did you use X server, such as VcXsrv?

@Antonio-Bennett
Copy link

Having the same issue as @Kelly510 any updates on that?

@ABD-01
Copy link

ABD-01 commented Apr 13, 2025

Hi
One might need to run sudo service ssh --full-restart if you are consistently facing can't open display even after having exact same config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment