MobaXTerm X11 forwarding issue with UNIX
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 videos on Youtube
overexchange
Updated on September 18, 2022Comments
-
overexchange over 1 year
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
errorEdit:
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.
-
VocalFan over 5 yearsMobaXTerm implements its own X11 forwarding, so you shouldn't need to use
xhost
. What was the value ofDISPLAY
as soon as you connected, before you changed it? -
JdeBP over 5 yearsA related question is unix.stackexchange.com/questions/111519 .
-
overexchange over 5 years@JigglyNaga
DISPLAY
value iswin_host_name:0.0
as soon as connected. I have added entries in.profile
and.bashrc
. -
VocalFan over 5 yearsSorry, 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 asxterm
) as the normal user, before yousudo
? -
overexchange over 5 years@JigglyNaga I have edited query with an answer for your query
-
VocalFan over 5 yearsDid you remove the "DISPLAY=..." lines from
.profile
and.bashrc
before doing that? -
overexchange over 5 years@JigglyNaga No, i did not remove. If I remove.. then
DISPLAY
variable will not be set.. -
VocalFan over 5 yearsThen please remove them and try again. MobaXTerm should have set up
DISPLAY
automatically. -
overexchange over 5 years@JigglyNaga After removing them, as soon as I connect I see
DISPLAY
not set. why would MobaXterm set it? -
VocalFan over 5 yearsWhat is the output of
grep X11 /etc/ssh/sshd_config
, on the server? -
overexchange over 5 years@JigglyNaga Where is it mentioend that MobaXTerm will set display variable?
-
VocalFan over 5 yearsThen X11 Forwarding is correctly set up on the server. Are you able to connect to it from another Unix/Linux machine and run X11 applications, as described in unix.stackexchange.com/questions/12755/… ?
-
VocalFan over 5 yearsFrom the accepted answer on the linked question: "Note that you do not need to set any environment variables on the server. DISPLAY and XAUTHORITY will automatically be set to their proper values. If you run ssh and DISPLAY is not set, it means ssh is not forwarding the X11 connection."
-
overexchange over 5 yearsBut this documentation says... you need to set DISPLAY variable explicily
-
VocalFan over 5 yearsFrom the section 'DISPLAY settings': "When you use a SSH connection, if the remote server supports X11-Forwarding, your DISPLAY is automatically set and it will be sent through the SSH connection to your Windows desktop."
-
overexchange over 5 years@JigglyNaga Firstly... why ssh client is showing wrong domain of windows name in last login msg?
-
VocalFan over 5 yearsLet us continue this discussion in chat.
-
-
overexchange over 5 yearsDISPLAY is showing
localhost:10.0
-
overexchange over 5 yearsWhat next? to forward X11
-
overexchange over 5 years
xterm
is also working -
VocalFan over 5 yearsIf
xterm
opens on your Windows machine, then forwarding is working. Are you still trying to run another X11 application (./setup
) as root, aftersudo
? If so, the set the two variables while in the root shell, as shown in the second part of the answer. -
overexchange over 5 yearsyes 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?
-
VocalFan over 5 yearsIf you've run the commands in the order I wrote them, then the
xterm
that appeared on your Windows laptop was started from inside thessh
session - ie. from the linux machine, over X11 Forwarding. It usesDISPLAY=localhost:10
to make that connection, and you don't need to change it. Butsu -
clears your environment, includingDISPLAY
andXAUTHORITY
, so you will have to set those variables manually before running an X11 program as root. -
overexchange over 5 yearsBut as per this answer... unix.stackexchange.com/a/469669/62659 variable
DISPLAY
should be set to windows machine... am not sure.. why you are recommend ing to set to local host? -
VocalFan over 5 yearsThe first half of that question is about connecting directly to a server without X11 forwarding, which mean accessing port 6000-something, and messing with
xhost
, and relies on there not being a firewall. Please scroll down to the second half, "The modern, secure way of using X11 is SSH-based X11 forwarding...". Or read the answers to "how to forward X" question I linked earlier.