You are on page 1of 11

Linux-Tip.

net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

X11 Forwarding using SSH


Wednesday, 06 June 2007 As I have explained earlier, there are different ways to connect to remote servers or workstations. You can use NoMachines NX server or the GPL solution called FreeNX. Other tools like RealVNC or VNC provide remote control software which lets you see and interact with desktop applications across the network. One way to enforce the traffic security is to use the SSH by the way of X11 tunneling or port forwarding. SSH was developed to replace the insecure telnet, ftp, rcp, rlogin, rsh software. FreeNX is already perfectly using this technology. In this article I will show, how to forward X11 using ssh without any additional software on the Linux site. Additionally I will explain how to run Linux applications on Windows XP clients using PuTTY and X-Deep/32. For instructive purposes, we will use a small scenario to explain what needs to be done. There are two machines we would like to access remotely: OpenSuse 10.2 running KDE Debian 4.0 running Gnome As client machines we will use OpenSuse with client ssh software but also Windows XP with Putty. From the perspective of SSH, the remote machine is the server and your local machine is the client. The workshop setup could look like this:

1 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

Step 1: Preparing the ssh server First, you must have your SSH package installed on the server. We will use the OpenSSH packages provided by the distribution. Please verify how to find and to install rpm packages in both distributions. In some cases it is already installed on the server (some installed it as standard packages). If you build the software from source, make sure to compile it with X forwarding support. The binary packages contain runtime X detection in SSH version 3.2 and above.

SoftLayer for Germany Cloud, dedicated, & managed hosting Amsterdam Data Center now open
Germany.SoftLayer.com

Also, make sure that you have the following line in your /etc/ssh2/sshd2_config file: AllowX11Forwarding yes

2 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

Thats it already! Start the sshd using one of the following commands: /etc/init.d/sshd start service sshd start

Step 2: Using a Linux client You may have noticed that Linux is using virtual consoles by using the Ctrl-Alt-F1(-F12) key combinations. Generally, there's no reason to leave the default console (virtual console #7) unless you are attempting to login again or to diagnose problems. Please switch for test purposes to other consoles like this: Ctrl-Alt-F2 - to a new shell prompt Ctrl-Alt-F12 - to a empty console Ctrl-Alt-F7 - back to the X graphical display As you have seen while using the keystroke Ctrl-Alt-F12, there is nothing really running on this console. Lets display the remote machine GUI here. We can later easily switch from your client to the remote machine using the appropriate key combinations. Login to your client machine, run KDE and open a console as a normal user (no root permissions needed). We will open a X session on console 12 using the following command: X :12.0 vt12 2>&1 >/dev/null &

3 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

This will send all unneeded output the bit bucket or black whole but will open another X window on console 12. If you now switch to it by using the Ctrl-Alt-F12 keystroke, you will see something like this (empty grey background):

Change back to you original graphical display using Ctrl-Alt-F7. Go back to the console you have used before and create a ssh connection to the remote server using the following command: xterm display :12.0 e ssh X user@192.168.10.5 &

4 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

User should be a valid user on the remote system and you can (certainly) replace the IP address by a valid domain name of the server. If you now switch back to console 12 (Ctrl-Alt-F12), you are getting a prompt after typing the correct password. This could look like this:

Start KDE on the OpenSuse remote machine simply by using the command kde

5 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

If you like to access the Debian machine instead, you have to use the following command: xterm display :12.0 e ssh X user@192.168.10.6 & Start Gnome on the Debian remote machine by using the following command gnome-session &

6 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

Please notice that in both cases a x-term window with logging information appears. You can minimize it but shouldnt close it. If you like to cancel the connection, simply close the xterm window or use the more direct way by using the Ctrl-Alt-Backspace keystroke. As I already mentioned before, you can now work on both machines and switch it by using the Ctrl-Alt-F7 and Ctrl-Alt-F12 key combination. Step 3: Using a Windows client Unfortunately we have to use additional software on the Windows site to get it running. We will use Putty to connect from the Windows XP client to the remote server. PuTTY is a free implementation of Telnet and SSH for Win32 and Unix platforms, along with an xterm terminal emulator. It is written and maintained primarily by Simon Tatham. If you like to use the X11 forwarding feature, you will need an X display server for your Windows machine, such as Cygwin/X, X-Win32, Exceed or X-Deep/32. This will probably install itself as display number 0 on your local machine; if it doesn't, the manual for the X server should tell you what it does do. We will use in this workshop X-Deep/32 as the X display server. Please download and install the software first. You will find a download link, detailed instructions and additional help on this webpage.

7 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

Open up the command putty.exe by double-click it. It will open the interface. First, setup the connection info in Host Name (or use IP) field and select SSH (using port 22). In the field Connection Category, find the Connection tree. In SSH, expand it and you will see Tunnels window. Click "Enable X11 forwarding". It is setting the default to X display at "localhost:0". Now, go back to Session and save this session with a name you like. Im normally using the IP address of the server.

8 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

9 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

With the X-Server running in the background, you should now be able to run X11 applications. In the next image you can see Linux application like xclock and konqueror running on a Windows XP desktop.

10 of 11

12/20/2011 10:33 AM

Linux-Tip.net - X11 Forwarding using SSH

http://www.linux-tip.net/cms/index2.php?o...

Close Window

11 of 11

12/20/2011 10:33 AM

You might also like