skip to Main Content

I’m trying to use ssh forwarding feature on mac to display remote GUI application locally.

on Mac, I installed the official xserver XQaurtz, set it up as below.

$ cat ~/.ssh/config
Host *
    XAuthLocation /opt/X11/bin/xauth
    ForwardAgent yes
    ForwardX11 yes

Then I used “ssh -v -X user@remote_machine” to login a ubuntu machine, then used xclock to test.

$ ssh -v -X user@remote_machine
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data ~/.ssh/config
debug1: /Users/bwu/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug1: auto-mux: Trying existing master

On remote machine, xclock failed to launch due to $DISPLAY is empty.

$ xclock
Error: Can't open display:

I did two more tests.

  1. From the same mac, ssh login to another centos 7 machine, it’s working. $ cat /etc/ssh/sshd_config X11Forwarding yes
    X11DisplayOffset 0

  2. From a ubuntu host, ssh login to above ubuntu machine, it’s working. $ cat /etc/ssh/sshd_config X11Forwarding yes X11DisplayOffset 0

So we got below results.

mac to centos, working
ubuntu to ubuntu, working
mac to ubuntu, not working
Test 1 indicates the issue might locate on remote ubuntu machine.
Test 2 indicates the issue might locate on local mac machine.

What’s wrong with this? Did I miss anything?

2

Answers


  1. Chosen as BEST ANSWER

    Further update on this issue. I noticed x11 forwarding did not work "randomly" on centos or ubuntu (from my macbook), but after a couple hours it may work again.

    I checked the sshd configuration on both centos and ubuntu, nothing special and they are same in x11 forwarding part. I don't know why.

    X11Forwarding yes
    X11DisplayOffset 0
    #X11UseLocalhost yes
    

  2. Here is a solution that might work. I had the same problem and this is how I solved it. Give the following solution a try.

    First find the DISPLAY variable.

    So in your mac if you type as a normal user

    echo $DISPLAY
    

    Then what you would get is something like the following.

    /private/tmp/com.apple.launchd.0aQYNoXMFK/org.xquartz:0
    

    Then try something like

    xeyes
    

    to see whether forwarding works. There are other apps you could try, but I like this one.

    And now you know that your display is working

    Now if you want to try the same as root (Please don’t jump on me guys, I know some of you all are strongly against root access) echo $DISPLAY, but if does not work

    then in your root prompt do the following

    export DISPLAY=/private/tmp/com.apple.launchd.0aQYNoXMFK/org.xquartz:0
    

    The same you found in your normal user account. Then copy your
    .Xauthority at /Users/normal user/.Xauthority to /var/root/.

    The .Xauthority file is already there, but this would over right it.

    cp /Users/normal user/.Xauthority /var/root/
    

    Of course the export might work, but there is no harm in doing the above.

    Now try the following.

    echo $DISPLAY
    

    And you should see the following

    /private/tmp/com.apple.launchd.0aQYNoXMFK/org.xquartz:0
    

    If you ssh into Ubuntu from normal user prompt then you do not need to do the root part, but since, I use root to ssh into my Ubuntu systems I often have to do this.

    Then when you ‘ssh into Ubuntu type

    echo $DISPLAY
    

    And you would see something like the following

    localhost:10.0
    

    The above would work if you have done all those other bits like forwarding and etc.

    Again, if you want to use root in your Ubuntu and if the echo $DISPLAY does not produce any response,

    then try the following (Assuming you are at root prompt).

    cp /home/user name/.Xauthority /root/.Xauthority
    

    Now try

    echo $DISPLAY
    

    again and you would see something like the following

    localhost:10.0
    

    For fun try

    xeyes
    

    Of course you could try xclock or any other as well

    And it works in my case. Hope this is helpful and would solve a problem like the one above or like mine that someone has come across and who spent a few hours on this problem while scratching head and trying to pull hair out like me :-)).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search