Running X-Window apps remotely

I’ve been using SSH (Secure shell) for a looooong time on my Linux based systems for remotely controlling my headless servers. During this week I had a guy over at my desk that wanted to have a look at some of my settings on my Ubuntu box to see the difference in configs between what he has done and what I have done differently. I quickly jumped into putty on my windows box (since that is my daily workstation because of VS2010 ) and connected to my server remotely.

Opened up nautilus on linux so I could visually browse to my config files (could have probably done this through shell  too), Nautilus then opened up in my windows OS as any other window would have. Since the other guy has never seen this he was obviously shocked to see the window appearing in my windows environment. I then went off to explain to him how this works and thought that I would share this since a couple of people have asked me “HOW DO YOU DO THAT” before, so here goes.

Remote-X (not the official name I think , but that’s what I call it ) is enabled via ssh or secure shell. SSH is a protocol used to securely access a Unix/Linux machines from another that allows you to run command line and graphical apps remotely and also for file transfers or creating secure networks over the internet to tunnel through(such as a remote http proxy or so). To accomplish this we would need 2 things.

  • Open SSH server for hosting and setting up the secure connection to the linux box that you want to connect to (Thus this runs on the server)
  • SSH client such as Putty to then connect to the server remotely via ssh protocol

Note that is a lot more uses for ssh such as secure ftp connections but I am just going to explain the basics to get a remote connection with openssh and remote X execution from a windows box.

Server Side Setup

First thing to-do is to get Open ssh setup on your Linux box (I am using Ubuntu 10.04 so my commands provided relates to Ubuntu).

Install Open ssh on your Ubuntu box via the following command

sudo apt-get install openssh-server

Once this is done you can change your configs as needed (have a look in the man file. man sshd_config for more info or just lookup sshd on the ubuntu site)

Now we just need to get the openssh daemon running and we’re set on the server side. This can be done with the following command.

sudo /etc/init.d/ssh restart
Client Side Setup

From a client side perspective , most machine would have a client to connect to a server via ssh such as putty. Ubuntu just needs the client downloaded to it and your set, since you have X-server doing all the X windows stuff on ubuntu by default, you won’t have a problem at all in opening the X-apps remotely that sits on your server.To get that client you can simply run the following command and then connect via that client once your set.

sudo apt-get install openssh-client

From a windows perspective, it is a tad more complicated because windows does not make use of the X- server natively for hosting or running its windowing system. In order to get that sorted we must do a couple of things as follows.

    • Download and install X-Ming a X-windowing server for windows.This will provide the capability to windows to run X-window apps within windows.
    • Download and install Putty used for connecting via ssh ( apparently X-ming has a way to connect to a server via ssh with its own mechanisms but I haven’t used that before. I prefer the familiar )

Once these 2 apps are installed you are all set to connect to your server.

Try Connecting ……

To check that the whole process as explained before was successful, we will try and connect to our Linux server over ssh.

    • Run xming and make sure you see the xming icon in your taskbar in the bottom right of your screen.

 

    • Now run putty and enter your server details

    • Before we connect we need to make sure Putty understands that we want to allow X-window apps to execute. Browse to the SSH settings in putty and expand that. You should see a sub option for X11, open that and then check that the X11 forwarding on the right hand is enabled.

    • You can now click “Open” and you should be connected to your remote server and prompted for the login details of that remote machine

.

    • Once logged in you can try and run a X-App to see that the remote server will then forward the X11 window to your windows machine.I usually run the following command to test: xcalc and will then be presentedwith the XCalc app in your windows environment

.

Sooooo , that’s quite a process on paper, but its actually very simple once you’ve tried it. You can then execute any X-window app remotely with convenience and this is very useful if you have multiple Linux of Unix machines that you work off.

Try this out if you have a remote scenario and let me know if you come right, if you struggle or have some questions.Drop me a comment or question and we’ll take it from there.

Happy computing. Ciao ciao