0

Ran below commands on MobaXTerm:

Using MobaXTerm terminal on windows laptop:

> xhost +ulv78.abc.com
ulv78.abc.com being added to access control list

> ssh -l someuser ulv78.abc.com # RHEL 7.x
SECURITY NOTICE:
Unauthorized use is prohibited. Use of this private computer system is your consent to being recorded and monitored. We reserve the right to seek all remedies for unauthorized use. Evidence of suspected illegal use may be given to law enforcement.
X11 forwarding request failed on channel 0
Last login: Thu Sep 20 12:06:57 2018 from win_host_name
$ bash
$ echo DISPLAY=win_host_name:0.0; export DISPLAY >> .bashrc
$ sudo su - # as root sudoer
$ echo DISPLAY=win_host_name:0.0; export DISPLAY >> .bashrc
$ cd /install_path
$ ./setup
Error: Can't open display: win_host_name:0.0

Above session has X11 forwarding request failed on channel 0 error

Edit:

Set DISPLAY entry in .profile & .bashrc. As soon as I connect from MobaXterm terminal, below is the output:

> ssh -l someuser ulv78.abc.com
SECURITY NOTICE:
Unauthorized use is prohibited. Use of this private computer system is your consent to being recorded and monitored. We reserve the right to seek all remedies for unauthorized use. Evidence of suspected illegal use may be given to law enforcement.
X11 forwarding request failed on channel 0
Last login: Thu Sep 20 12:36:54 2018 from win_host_name
$ echo $DISPLAY
win_host_name:0.0
$ xterm
xterm: Xt error: Can't open display: win_host_name:0.0
$

1) How to resolve X11 forwarding error?

2) I see wrong domain name showing in the last login msg of ssh client.

  • MobaXTerm implements its own X11 forwarding, so you shouldn't need to use xhost. What was the value of DISPLAY as soon as you connected, before you changed it? – JigglyNaga Sep 20 '18 at 16:36
  • A related question is unix.stackexchange.com/questions/111519 . – JdeBP Sep 20 '18 at 16:40
  • @JigglyNaga DISPLAY value is win_host_name:0.0 as soon as connected. I have added entries in .profile and .bashrc. – overexchange Sep 20 '18 at 16:43
  • Sorry, I mean: what was it before you added those lines to .bashrc and .profile (you might need to delete those lines again in order to find out)? And could you run an X client (such as xterm) as the normal user, before you sudo? – JigglyNaga Sep 20 '18 at 16:45
  • @JigglyNaga I have edited query with an answer for your query – overexchange Sep 20 '18 at 16:48
2

X11 forwarding (as the initial user)

MobaXTerm supports X11 forwarding, enabled by default. If X11 forwarding is enabled on the linux server (ulv78), then DISPLAY is set to an apparently local address, and your ssh client forwards those requests back to your X11 server (running on your Windows machine). See How to forward X over SSH to run graphics applications remotely? for more details about how this works.

When this is setup correctly, you should not change the DISPLAY environment variable yourself; if you've added lines to your login files (.bashrc etc) to set it, you'll have to delete them again. Your should see results like this:

ssh -l user ulv78.domain.com

(Now running as user on remote machine)

user@ulv78$ echo $DISPLAY
localhost:10
user@ulv78$ xterm

xterm is used as a test app here. It should appear on your Windows machine, despite being started by the remote Linux machine. Its prompt will indicate that you are user@ulv78, rather than MobaXTerm's initial prompt.

Congratulations, that's the first step. X11 forwarding is working. Now on to the advanced part:

Accessing the X11 server as another user

When you switch to another user (such as root) via su - and try to run graphical applications on the same X server, you'll discover that your environment variables have all disappeared. This is when you do have to change DISPLAY manually, as well as copying the X credentials with the xauth(1) command (instructions based on https://blog.mobatek.net/post/how-to-keep-X11-display-after-su-or-sudo/ ):

ssh -l user ulv78.domain.com

(Now running as user on remote machine)

user@ulv78$ echo $DISPLAY
localhost:10
user@ulv78$  xauth list | tail -n 1
ulv78/unix:10  MIT-MAGIC-COOKIE-1  4fa72fbe2b05ebe3f047a1b0430ecf6a
user@ulv78$ sudo su -

(Now running as root)

root@ulv78$ export DISPLAY=localhost:10    # <- copied from above
root@ulv78$ xauth add ulv78/unix:10  MIT-MAGIC-COOKIE-1  4fa72fbe2b05ebe3f047a1b0430ecf6a # <- copied from above
root@ulv78$ cd /install_path
root@ulv78$ ./setup

The ./setup application will now appear on your Windows machine, just like the xterm did earlier.

  • DISPLAY is showing localhost:10.0 – overexchange Sep 20 '18 at 21:23
  • What next? to forward X11 – overexchange Sep 20 '18 at 21:31
  • xterm is also working – overexchange Sep 20 '18 at 21:36
  • If xterm opens on your Windows machine, then forwarding is working. Are you still trying to run another X11 application (./setup) as root, after sudo? If so, the set the two variables while in the root shell, as shown in the second part of the answer. – JigglyNaga Sep 21 '18 at 0:21
  • yes xterm opens on my windows laptop. Now, how do I launch installer from linux machine? Your second part of the answer does not help me., because display should be set to windows machine. Isn't it? – overexchange Sep 21 '18 at 1:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.