# Use X remotely

## sKewlBoy

I've been using gentoo for a few months now (and linux for a few more time), but I've never set up X to run remotely.

I've been around config files and manual pages but I can't seem to find any info on that.

Is there any URL where I can find a guide to use XFree as server and client ?

Or is there anyone who can give me some tips ?

Like, I have my desktop computer, and then a older one as firewall and webserver. I now want to run X apps in my server.

Thank you

----------

## ebrostig

 *sKewlBoy wrote:*   

> I've been using gentoo for a few months now (and linux for a few more time), but I've never set up X to run remotely.
> 
> I've been around config files and manual pages but I can't seem to find any info on that.
> 
> Is there any URL where I can find a guide to use XFree as server and client ?
> ...

 

Easy  :Smile: 

First type:

xhost +<name-of-your-server>

Telnet to your server.

run: export DISPLAY=<ip or hostname of your pc>:0.0

ie: export DISPLAY=mypc.com:0.0

Then execute any X-based program on your server, the output will be displayed locally on your PC.

Erik

----------

## squanto

You may want to use ssh rather than telnet, more secure. I believe that there is an option in /etc/ssh/sshd_config that is "#X11Forwarding no" and has to be uncommented and changed to yes before this will work with ssh.

I have not tried this yet, working on it now, and will let you know what my results are.

-Andrew

----------

## bcavalieri

Check out www.ltsp.org, I use remote x display's for some school computer labs, and use the ltsp packages to do it.

If cups would ever work I would use gentoo, but have to rh till then.......

----------

## ebrostig

 *bcavalieri wrote:*   

> If cups would ever work I would use gentoo, but have to rh till then.......

 

ooppss... what's wrong?

Maybe if you post a new thread on your Cups problems, we can be of some kind of help to you.

I'm sure we'll get it to work!

Erik

----------

## RagManX

As mentioned, use ssh instead of telnet.  On your ssh server, modify your sshd_config file so you have the line

```
X11Forwarding yes
```

in it and uncommented.  Then, restart your sshd (kill -SIGHUP sshd_PID).  Now, when you want to connect to that server, use:

```
ssh -X username@servername
```

and connect.   I would recommend *NOT* connecting as root, but many people don't have that hangup.  Login as a normal user, and any X commands you run on the remote server will automagically be forwarded for display on your local host.  You don't need to add anyone via xhost, and you shouldn't need to set your DISPLAY variable.

RagManX

----------

## AlterEgo

VNC is very easy to set up and achieves the same.

emerge vnc; www.realvnc.org for questions&answers.

----------

## sKewlBoy

Thanks, guys! So much help in such a few time =)

I'll give it a try.

I would never use telnet, but I understood the point.

Then again, I will probably use ssh X11 forwarding a RangMan suggested, since it looks the easiest way and more secure.

Just one question for it then:

If I use sshd X11 forwarding option then I won't need port 6000 open in the firewall will I ? I mean, I think, since I use ssh to run X and encrypt X data, it will use port 22 to communicate from my PC to my server, right ? Probably sshd will then communicate with X (running on the server) through 600 but that's local access, right ?

And, btw, do I have to run startx in the server or will sshd take care of it, when I "ssh -X" into it ?

Thanks

----------

## sKewlBoy

well, I didnt quite understood, rangmax

after enable x11 forward and restart sshd in my server, I "ssh -X skewlboy@myserver" and then what ?

I get a shell... I thought ssh would start X automatically ...

----------

## sKewlBoy

Oh jeez... I'm such an ass =\

I got it working, thank you guys! =)

----------

## theclaus

Can you explain how? I tried to get mine to work and no go.

----------

## pato

ssh -X user@myserver <command> should work if X Forwarding is enabled. If it doesn't, are you receiving any errors, or does the command just hang?

----------

## jimlynch11

sorry to bump an oooold thread, but how do i do this from putty in windows? right now when i ssh in and do startx, it barks saying the screen is unavailable (im running X locally on the machine im ssh'ing into)...how do i tell it to start a second X session?

thanks!

----------

## sKewlBoy

you dont "startx" with X forwarding  :Smile: 

If you start putty with X forwarding just execute the X app you want and (if you have a X server running on your windows machine) it will popup.

Samba plus X Forwarding is great for merging windows and linux.

----------

## ctford0

You cant run X11 thourgh putty, however you can use xwin32 or cygwin.  As far as I know putty doesnt have the ability to transmit X11 through ssh, I think it is the same reason you can't start a remote X program from the console or a local program for that matter.  Pretty sure you have to have X11 server running locally even though your executing a remote app.

Chris

----------

## RagManX

 *jimlynch11 wrote:*   

> sorry to bump an oooold thread, but how do i do this from putty in windows? right now when i ssh in and do startx, it barks saying the screen is unavailable (im running X locally on the machine im ssh'ing into)...how do i tell it to start a second X session?
> 
> thanks!

 

As already mentioned, you can't do this with Putty.  The way X forwarding works is you need to have an X Server on your local display.  Then, connect to a remote X capable system with

```
ssh -X username@machine
```

and from the command prompt you get after logging in, run whatever commands you want.

As an example of how I use this, I use multiple Linux servers at work for various security tasks.  I must run Winderz as my desktop, unfortunately.  To take advantage of my Linux systems, I have installed Cygwin (http://www.cygwin.com/) on my Windows desktop (make sure to install XFree86 when installing it).  Once I log in to my Winderz machine, I start the cygwin shell, and from there run:

```
startx&
```

to get into X.  Within X, I start an XTerm, then run the above listed ssh command.  Once connected to my remote Linux system, I can run mozilla and it will display locally on my Cygwin X display without any further work on my part.  No setting of my DISPLAY variable, no opening ports, nothing.  Everything that happens between me and the remote Linux server gets tunnelled over SSH.  So, as long as you can SSH to a machine, you can take advantage of any X capable program.

Hope that helps.

RagManX

----------

