X11 forwarding and SSH for remote linux / ubuntu desktop

Here’s something I used earlier..

Connecting to Remote Linux Desktop via SSH with X11 Forwarding

by Forrest Sheng Bao http://fsbao.net

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, everything software 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 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 connecting my Linux box remotely with a graphic desktop environment, I have many choice, VNC (or VNC over SSH, VNC over VPN), SSH with X-window enabled, 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 at your client so the data to transfer thru network is not huge. You won’t feel the screen is delayed even when you play movies. And this won’t add your server much load, as the same reason, thus a lot of job is done by your client. So, this is a high efficiency 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 a 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 their docs on how to start them.

Try to 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!

SSh to Linux box from Mac

13 Replies to “X11 forwarding and SSH for remote linux / ubuntu desktop”

  1. I see a lot of interesting posts on your website.

    You have to spend a lot of time writing, i know how to
    save you a lot of time, there is a tool that creates readable,
    SEO friendly posts in couple of seconds, just type in google – k2 unlimited content

  2. under debian wheezy the restart of the x-server is:

    /etc/init.d/ssh restart

    this takes me a little time to find out. maybe it helps saving searchtime for some other unexperienced user.

  3. thanks a lot. i have tried to get it done several times. but now it works. this is the clearest straightforward howto i have found so far. you are great!

  4. The only problem with late night snacking is that there is not
    much activity done after that. Protein is not the
    only food that is beneficial to burning belly fat.
    Even thought the amount of calories is lesser than of fat, alcohol calories are completely useless.

  5. I’ve been surfing online more than 3 hours these days, but I never discovered any fascinating article like yours. It’s pretty worth enough for me.

    In my view, if all site owners and bloggers
    made excellent content as you did, the internet can be a lot more helpful than ever before.

    Also visit my weblog; best shared hosting alternatives,

  6. For those who get an empty $DISPLAY env var on the Mac: I figured out that Apple has silently removed X11 from their OS recently!

    Details see here: http://goo.gl/EzPWa – I’ve installed the mentioned XQuarz on the Mac and then things worked.

  7. great write-up
    all things works well until when i tried gnome-session
    i got
    ** (gnome-session:1487): WARNING **: Cannot open display:
    pls help

  8. i got ubuntu on an ESXi box, and I have access remotely to it, I’ve followed the process but when I do: startx on the Mac X11 client it brings up the KDE in the ESXi console and not in the MAC, i think it’s related to the DISPLAY variable but i dont know what to do really?, any suggestions?


  9. If you can help thanks. How can I configure a Linux computer to listen to an already forwarded application? I have a single application in a Debian computer, and it can be accessed by different users at the same time, so it can forward the login screen to any computer knowing it IP address. So, it is already forwarding the applicaiton, but I cannot make the other computer to listen and respond to it (it has Ubuntu 11).

  10. Perfect, Nice job Chemmyone thats exactly what I was always looking for in the mighty world of linux. It all comes at the best of time. keep it up.

Comments are closed.