Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X11 Forwarding for non-root user not working

Cross-Posted

Environmental Details

Relevant bits of server's /etc/ssh/sshd_config:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no

Relevant bits of client's $HOME/.ssh/config:

Host *
    XAuthLocation /opt/X11/bin/xauth
    ForwardX11 yes
    ForwardX11Trusted yes

Using XQuartz on macOS High Sierra.

The Problem

I'm spinning up a vagrant Ubuntu 18.04 VM. I've added a second user outside of the vagrant user.

ssh -X vagrant@ubuntu-bionic xclock

I can get X11Forwarding to work when I login as the vagrant user. I cannot get X11Forwarding to work when I login as the ops user.

ssh -X ops@ubuntu-bionic xclock

X11 forwarding request failed on channel 0
Error: Can't open display:

I want to be able to get it to work with the ops user. From the client, $DISPLAY has a value. When I login with vagrant, $DISPLAY has a value. When I login as ops, $DISPLAY is unset. If I set $DISPLAY to match what it is with the vagrant user, I get the same error:

Error: Can't open display: localhost:10.0

when X11UseLocalhost yes

Error: Can't open display: ubuntu-bionic:10.0

when X11UseLocalhost no

If I login as ops and then sudo su - vagrant, $DISPLAY remains unset. If I login as vagrant and then sudo su - ops, $DISPLAY is inherited.

What am I missing to get this to work? I've run xhost + in each user (including sudo -s root xhost +) and it still doesn't work.

If I add -vv to my ssh commands, I see this message when connecting as vagrant:

X11 forwarding request accepted on channel 0

and as ops:

Remote: X11 forwarding disabled in user configuration file.
X11 forwarding request failed on channel 0
like image 388
John Jelinek Avatar asked Apr 27 '18 22:04

John Jelinek


1 Answers

I don't get the whole topic, but for my very similar situation it helped to create the users~/.Xauthorityfile. I copied it from the vagrant users home directory and then set the new ownership.

like image 199
Andreas Brodbeck Avatar answered Nov 17 '22 14:11

Andreas Brodbeck