How to tunnel X over ssh

This is going to be a miniature “howto” tunnel X over SSH. It was tested on a Windows XP Pro. w/SP3 and CentOS release 4.8 (Final).

I really love PuTTY: a free telnet/ssh client but running it on as many instances as I need, just doesn’t cut it. So I gave PuTTY Connection Manager (aka: PCM) a try, but that software wasn’t stable enough, slow and didn’t have the usability of working Linux vs. Linux as I wanted.

What I was looking for, working on Windows, not installing heavy doses of Cygwin or its alternative, and keep it simple as I can. The solution I was thinking about, was using PuTTY to SSH to my Linux box, then open up Konsole (My favorite X terminal) and have it pop open on my Windows machine. How could would that be, ah!?

There is catch. How do Windows and Linux speak to each other (In this particular situation)? Well, it all about setting up an X server that’ll grab the “calls” that my Linux box sends to my Windows machine, and letting them through.

So some really go all the way out, as far as installing Cygwin and stuff. I didn’t go that path. I installed FreeXer – free-X-server.

I’m in no way inventing the wheel here… this has been used by people since way before I even knew what Linux or maybe even Windows were… but I thought I’d share my two cents with you now.

So how did I acomplish this nifty deed? It was quite easy, I must admit, but not for the faint of heart, if you don’t have a bit of experience with any/all of the aforementioned titles I’ve thrown your way.

Now, for the deed:

  • First lets install some X on the server and the xclock for some fancy tests.
    • On the Linux box: $ yum install kdebase xorg-x11-tools.i386
    • As root, you might even want to check that your SSH server allows you do X11 forwarding:
      • # grep X11Forwarding /etc/ssh/sshd_config
        X11Forwarding yes
  • Now I’ve downloaded and install FreeXer. Its a plain old “Next Next Next” installation and at the end, it’ll either start it up (I can’t recall) and you’ll have the big black X at the system tray, or you’ll need to start it (Find it in Start -> Programs -> FreeXer)
  • Now I’ve downloaded PuTTY and this part is very important, when you set it up to connect to your Linux box, make sure you:
    • Expend Connection -> SSH -> X11
    • Tick the check box “Enable X11 forwarding”
    • In “X display location” field type: localhost:0
    • Now login to the Linux box and type:
      • $ env |grep DISPLAY
  • Now that I’m logged into the Linux box, and I see that the X11 forwarding is good, I should be all set!
  • Type: xclock &
    • Did the xclock popup? Good!
    • Didn’t? Well, post your reply below 🙂
  • If it did, then why not close xclock and start Konsole?
    • $ konsole &



Tags: , , , , , , , | Posted under Linux Usability | RSS 2.0

Leave a Reply

Your email address will not be published. Required fields are marked *