Connecting to Remote Linux Desktop via SSH with X11 Forwarding

by Forrest Sheng Bao http://fsbao.net

Update (2013-09-09): If you have trouble with full screen on Mac OS X, my friend Dr. Changzhi Li has a suggestion: "In X11 preference, enable Full Screen Mode under 'output', then it gives you full screen and complete control of Linux desktop."

There are two advantages of Linux, compared with many other operating systems, such as Windows and Mac OS X. The first advantage is the ultimate B/S architecture. Thus, every program is either a server or a program running on a server. When clicking my mouse, I am talking to a server program called X Server on my box. When surfing the Internet, I am using Firefox, a browser running on X Server. The second advantage is that you can always find many choices to achieve one goal. When I wanna connect to my Linux box remotely with a graphic desktop environment, I have many choices: VNC (or VNC over SSH, VNC over VPN), SSH with X-window forwarding, xdmcp, etc. Here we will discuss how to connect to your Linux desktop via "ssh -X". It's very easy, you just need to type two more letters than common SSH connection.

Why "ssh -X"? Because the graphic rendering job is done on your SSH client (and thus your X server) so the data to transfer thru network is not huge. You won't feel the screen laggy even when you play movies. This won't add to your SSH server much load, for the same reason. A lot of job is done by your X server (your SSH client). So, this is a very efficient solution for remote desktop. You even can run big commercial graphic software, like Xilinx ISE or Mathworks MATLAB, remotely. And, this supports multi-client, no matter using different username or same username, since you are connecting to a server, both SSH server and X server.

Of course, you need to properly install and configure your SSH server, which is on the same machine running your Linux graphic desktop environment (KDE, GNOME, Xfce, or whatever). Obviously, you MUST install your SSH server program. You can install it via "sudo apt-get install openssh-server" on Ubuntu Linux 7.10. I think you can easily figure out how to do so on other Linux distributions. Then edit the file /etc/ssh/ssh_config. Make these lines be in that configuration file:
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes

Now open /etc/ssh/sshd_config. Attention, the file name is sshd_config, not the same as previous one. Make sure this line be in this configuration file
X11Forwarding yes

Restart your SSH server. Now, go to your client computer, from which you will connect to this computer.

I have no idea on how to do next on Windows. If your client computer runs on Linux or Mac OS X, or other OS with X server running, go ahead.

If your client computer runs on Mac OS X, make sure that you have installed X11 for Mac OS X. Go to "Application"- > "Utilities" to start X11 and you will see an xterm terminal in front of you by default. If no such window, click "Applications" - > "Terminal".

Now let's simply type
ssh -X user_name@the_server_IP_or_hostname.domainame
. For example, if my server is www.example.com and my username is NSF, I simply type
ssh -X NSF@www.example.com
. Accept the RAS key and enter your password.

Have logged in? Ok, the big show is coming. If your desktop is GNOME, then just type
. What do you see? The GNOME desktop is in front of you. If your desktop is others, such as KDE or Xfce, please refer to their docs on how to start them.

Try to do something, and you will really find that the networked remote desktop is very fast. You can even play movies. No delay, right? As I just said before, the graphic rendering job is done at your client so the data to transfer thru network is not huge. It's just like when you play a 3D network game, like World of Warcraft, only some instructions are transferred thru the Internet but not all 3D objects.

This is my desktop connecting to remote Linux box from a Mac. The left-top corner lays Xlinx ISE. The left-bottom is playing 2008 New Years Concert. I put the Mac info page over the Linux desktop. Like it? DIY, now!


Anonymous said...

Thanks for your tips!

But you probably made a mistake on the X Window server/client concept. The X Window server is responsible for the graphic rendering, while the client is for caculation. Since you are connecting to a Linux box using your Mac box, the X server is actually running on your Mac and the client is runing on the Linux.

You can reffer to this article for more information.

Forrest Bao said...

Here client means the SSH client. To follow the common sense, the computer who connects to a remote computer is the client.

Anonymous said...

Super helpful, Thanks ! I am using my first Mac and this was easier than I had expected.

Anonymous said...

very short and sweet. worked perfectly.

Unknown said...

Exactly what I needed for the MAC side!

Thank you,

Rob McKennon

$hulgsta said...

Awsome! XP
Thanks for the comprehensive instructions.

Unknown said...

What does B/S stand for?