MobaXTerm – Fix X11 Forwarding Issue with UNIX

linuxmobaxtermsshssh-tunnelingx11

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.

Best Answer

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.

Related Question