# How do you get X11 forwarding to work?

## TazG

I have Cygwin at school and I want to try X11 forwarding with SSH. (I want to see and control the graphical programs that are on my computer at home.) I can run X programs that come with Cygwin OK, and I can SSH to my computer OK. But if I try to start an X program on my computer, it says "cannot open display".

----------

## Peracles

 *TazG wrote:*   

> I have Cygwin at school and I want to try X11 forwarding with SSH. (I want to see and control the graphical programs that are on my computer at home.) I can run X programs that come with Cygwin OK, and I can SSH to my computer OK. But if I try to start an X program on my computer, it says "cannot open display".

 

You need to use 'xhost +'.  This allows external X windows to pop up on the machine you are using.  Just open up a console or terminal on your machine and enter in the command.  man xhost to see the info on it.

----------

## Little Nemo

xhost only controls who is allowed to access the X server.

To enable X11 forwarding, you need to set X11Forwarding to "yes" in your sshd server's /etc/ssh/sshd_config, and ForwardX11 to "yes" in the ssh client's /etc/ssh/ssh_config (an alternative is to use the "-X" option to ssh.

In this case after logging in to the sshd server, you should find that the $DISPLAY variable is set to localhost:10.0 (or whatever offset you defined in /etc/ssh/sshd_config). You can then connect to the X server on the ssh client, provided that the X client (the sshd server) is allowed to connect.

----------

## andyknownasabu

 *TazG wrote:*   

> I have Cygwin at school and I want to try X11 forwarding with SSH. (I want to see and control the graphical programs that are on my computer at home.) I can run X programs that come with Cygwin OK, and I can SSH to my computer OK. But if I try to start an X program on my computer, it says "cannot open display".

 

You also need the -X switch of ssh to enable X-Forwarding (therefore it has to be enabled on the server side...)

----------

## TJNII

Also, if the window fails and you get a cryptic "BadWindow" error, try connecting with the -Y option.  It is a trusted host option, and I'm not 100% sure what security issues it intails, as I usually only throw X over my trusted network.

----------

## mthimm

First of all, the xhost + command shouldn`t be entered never, except for debugging purposes without connection to any network.

It disables access-control at all, so everyone can grab any X Event from your Display (This includes the cleartext keystrokes, when you are typing your password in order to start your encrypted ssh session). In addition it is easy to grab your entire screen to see what you are doing, or to start funny little programs like xroaches or xlock (which you cannot unlock, since you do not know the passwort) on your display.

So X11Forwarding should be the right way.

You should have 

```

ForwardX11 yes

ForwardX11Trusted yes

```

in the ssh_config of your client (TrustedX11 forwarding is a small security risk) and

```

X11Forwarding

X11DisplayOffset 10

X11UseLocalhost yes

```

If you log on with 

```
ssh -l username -X remotehost 
```

 you should get localhost:10.0 as $DISPLAY.

Actually this does not work with my installation, I get localhost:0.0 in $DISPLAY and I do not know why. When I set DISPLAY to localhost:10.0 X11 forwarding works fine.

----------

## TazG

So the first 2 lines are for the school computer and the other 3 are for home...?

It still says can't open display.

----------

## piffle

I cannot get X11 forwarding to work lately too, either with SSH X11 forwarding or with the oldstyle "xhost+" I used for years.  As near as I can tell with netstat, nothing is even listening on the X ports.  Is tehre some reason Xorg would not listen for connections? I couldnt see anything untoward in the config file.

----------

## Raffi

For recent generic X11 forwarding problems, check out

```

http://forums.gentoo.org/viewtopic.php?t=249655&highlight=pamenv+display+ssh

```

For the original cygwin problem, what X server are you using with cygwin (sorry if you already said, I did not see it when going over the thread).

----------

## battra

This is probably off-topic but - if you want view X programs running on your home computer from your school computer:

```

# emerge tightvnc

```

----------

## TazG

Hey battra! I looked at VNC and I think it is what I want.

I have tightvnc viewer installed at school and I have been following the directions here... but I still can't get it to work.

Here's what I did:

From school:

```
ssh -L 5900:localhost:5900 taz@[my IP address] 'x11vnc -display :0'
```

And I get this:

```
viewonly:   0

shared:     0

conn_once:  1

mod_tweak:  0

loc_curs:   1

mouse:      0

root_curs:  0

defer:      30

waitms:     30

take_naps:  0

threads:    0

fs_frac:    0.60

gaps_fill:  4

grow_fill:  3

tile_fuzz:  2

use_hints:  1

Using display :0

PORT=5901

Read initial data from display into framebuffer.

using 32bpp depth=24 true colour

19/11/2004 12:36:18 Autoprobing TCP port

19/11/2004 12:36:18 Autoprobing selected port 5901

screen setup finished.
```

Then I start vncviewer.exe and for "VNC server":

```
localhost:0
```

 but when I try to connect x11vnc says

```
channel 2: open failed: administratively prohibited: open failed
```

----------

## thecooptoo

If they will let you use putty ( on a windows machine, I run it & windows VNC viewer from a floppy so im not actually 'installing' anything)

What ive done :

on my linux box , as a user ( with access to xhost - as root it gives an error message)

bash#vncserver

start another X session as dispaly :1

in putty configure an SSH connection to your server.

In the 'tunnels' bit check X-forwarding .

the local connection is L 5900

The remote connection is 192.168.0.8:1 ( on the LAN)

start putty & the SSH connection 

bring up the vncviewer from the floppy 

put localhost:0 in the litle box.

It asks me for my linux root password, and connects

 :Wink:   :Wink: 

----------

## shadow255

 *Raffi wrote:*   

> For recent generic X11 forwarding problems, check out
> 
> ```
> 
> http://forums.gentoo.org/viewtopic.php?t=249655&highlight=pamenv+display+ssh
> ...

 

Here's a clickable hyperlink for that forum topic:

https://forums.gentoo.org/viewtopic.php?t=249655

----------

## hoochiepapa

 *piffle wrote:*   

> I cannot get X11 forwarding to work lately too, either with SSH X11 forwarding or with the oldstyle "xhost+" I used for years.  As near as I can tell with netstat, nothing is even listening on the X ports.  Is tehre some reason Xorg would not listen for connections? I couldnt see anything untoward in the config file.

 

If you are running gdm, run gdmsetup

under the security tab uncheck the last box (Always disallow TCP connections)

restart X,  netstat -an | grep 6000  should something like 

tcp        0      0 0.0.0.0:6000            0.0.0.0:*               LISTEN

this shouldn't be required for SSH  X forwarding.

----------

