Articles » A (Linux) Server for Software Developers » Remotely use the Server via SSH and X-Windows

Remotely use the Server via SSH and X-Windows

X-Windows and OpenSSHOnce a Linux server is up and running, it could quite easily be put in a corner without monitor or keyboard. However, from time to time it is necessary to access that machine directly. It would be nice if it could be controlled remotely, desktop and all. With Linux, this is easy to do since it has no shortage of networking services that could be used. Also, X-Windows - the base windowing system - is designed to operate over a network, so it is possible to remotely use the entire desktop. All that is required is a little effort in order to set everything up. This page gives instructions for setting up the server for remote access via X-Windows via SSH. Special attention is given to the extra steps needed in order to remotely access the server from a Windows machine.

Installing Everything

  • Download and install X-Cygwin onto the Windows machine from which remote access is required (Linux users can skip this), and
  • Set up the Linux server and remote machines for secure access over SSH as per the instructions on this page.

Accessing the Server Remotely

  • Start X-Cygwin (Linux users just log in to the desktop and open a terminal window), 
  • Log on to the remote server via SSH with X-Windows forwarding enabled (replace "username" with your actual username, and "hostname" with the URL or IP address of the server):
ssh -Y username@hostname
  • That is it; you have access to the server. The X-Windows functionality  can be tested by starting an X-Windows application from the terminal, e.g. the following should open text editor that displays on the remote machine:
gedit somefile
NOTE: To execute a program in a new process so that you can continue to use the terminal, append an & to the end of the command, e.g.:
gedit somefile &

Remotely Accessing the Server's Desktop

The procedure above allows the user to remotely run applications on the server and display them on their own machines. Often this is all that is required. Sometimes, however, it may preferable to remotely access the complete desktop. Assuming that this is a server using the Gnome deskop, this can be achieved via the gnome-session command once the SSH connection is established. X-Cygwin users do have one issue with the default way that X-Cygwin is started; namely, X-Cygwin's default behaviour is to open a new Windows window for every X-Windows window. This is not the desired behaviour when running a complete desktop environment remotely. The easiest way to fix this is to create another start up batch file with the correct command line options:

  • Open the file c:\cygwin\bin\startxwin.bat in a text editor and save a copy as c:\cygwin\bin\startxwin_singlewindow.bat,
  • In the startxwin_singlewindow.bat file, remove -multiwindow from the following line:
%RUN% XWin -multiwindow -clipboard -silent-dup-error
  • the line should now read:
%RUN% XWin -clipboard -silent-dup-error
  • Save the file. It might be an idea to create a shortcut to this batch file in the start menu,
  • Start X-Cygwin by executing the new batch file, startxwin_singlewindow.bat (double-clicking on the file will execute it), and
  • Connect via SSH and start a Gnome session:
ssh -Y username@servername gnome-session

What to do When the Gnome Session Does Not Wake Up

As of writing this (28 November 2009), Gnome's screen saver will turn the remote screen black, and then refuse to wake up again (at least when using it with X-Cygwin). This occurs when it enters power saving mode. Killing the screen-saver will bring back the session.

Final Words

The above steps should allow complete use and administration of the machine remotely. It is perfectly possible to use X-Windows via the internet if  the router firewalls are set up correctly. However, performance may be poor due to the volume of information that must be transferred in order for X-Windows to work. This is really of greatest use within a Local Area Network (LAN) where one machine (or multiple) is the main Workstation from which all other machines are controlled. Since wireless connections are generally slower than wired connections, it is also recommended that all machines are connected via Ethernet instead of wireless connections, wherever possible.





Articles » A (Linux) Server for Software Developers » Remotely use the Server via SSH and X-Windows