39

Why would you use VNC (or for that matter NX) instead of just using ssh -X (-Y). I read that VNC uses less bandwidth, but is there any other differences/advantages with respective tool?

4 Answers 4

39

Aside from bandwidth and latency issues (which can vary a bit), the big differences are the functionality it provides.

VNC exports a whole session, desktop and all, while ssh will run a single program and show its windows on your workstation.

The VNC server exports a session that survives even when you disconnect your screen, and you can reconnect to it later with all the windows open etc. This is not possible with an ssh X tunnel, since when your X server dies, the windows go away.

4
  • 7
    That's the biggest reason I always use VNC, never direct X window. (I use VNC over a ssh tunnel). When I close the lid on my laptop, the connection is broken. With ssh -X, there is no way to resume -- I have to re-start the application from the beginning. With VNC (both direct and over a ssh tunnel), I can reconnect and continue right where I left off.
    – David Cary
    Sep 14, 2010 at 17:06
  • 13
    Although a bit OT (since this Q is presumably only about GUI apps): if an actual GUI app is not required, and just basic shell access will do (e.g., xterm), then do "ssh" followed by "screen bash". If disconnected (laptop closed,vpn disconnected, etc), the remote shell stays active. Re-login & re-connect via "screen -r". I only bring this up since I've seen people run vnc just for basic shell access (or run a remote xterm displayed locally); most of the time (but of course not always), simple shell access will suffice.
    – michael
    Nov 16, 2012 at 11:38
  • 1
    @michael_n I am interested to this thing you say about screen bash, but I am not able to make it work. I typed 'ssh -X -t myusername@remotehost screen bash' and after the connection drops I type 'screen -r', but it says 'there is no screen to be resumed'. what should I do?
    – simona
    Nov 21, 2012 at 12:34
  • 3
    @simona after the successful ssh login, then run screen: ssh user@host ; and after logged in: screen bash ; to disconnect, ctrl+a followed by ctrl+d. You can logout and login again, then: screen -ls and screen -r. Exiting bash exits the screen session. For more (much more), see various tutorials on GNU screen
    – michael
    Nov 29, 2012 at 9:25
12

ssh -X redirects X11 commands to your local X server. So it is as if you were running the program locally, when it's really running on the computer at the other end. It's very slow because it uses a great deal of bandwidth. (This is what people are talking about when they say X11 is "network transparent.")

VNC and other remote desktop apps instead let the other computer process all of the graphics drawing and so forth and captures, in essence, a screenshot and sends that back to your computer. It can seem much faster, because far less information is required to display everything. However, it also sends the whole desktop, rather than a single application.

I don't recommend using ssh -X over the Internet for one simple reason: It will use all of your available bandwidth. It's fairly useful over a LAN, in my opinion, so if you just need one application and don't want to have to run a whole desktop, this is a good way to go. Otherwise, just use VNC.

3
  • 3
    "It's very slow because it uses a great deal of bandwidth. The X11 protocol is very complex and often involves sending large pixmaps back and forth across the connection." - this is wrong, the X11 protocol isn't very complex and it doesn't involve sending large pixmaps back and forth across the connection. Come and join this proposal to learn more about the X Window System: area51.stackexchange.com/proposals/20129/the-x-window-system
    – delete
    Sep 13, 2010 at 4:09
  • 1
    @Sherlock: Well, the fact remains that it uses a lot of bandwidth. I deleted the offending sentence.
    – greyfade
    Sep 13, 2010 at 4:19
  • 1
    NX is an efficient way to transmit X11 protocol data over the network. It compresses the data, provides extensive caching and tunnels sessions over SSH. Sep 15, 2010 at 16:43
5

VNC will share an entire desktop from a remote system. It requires a full-fledged desktop on the remote system.

ssh -X allows you to run single X application from a remote server. The remote system does not need to be running a complete desktop, and you often only need a handful of packages to be installed on the remote system.

ssh -X can be useful when installing complex software packages over a remote connection. Some software products may use a GUI installer (Oracle Database, etc). I don't want to install and a full-fledged Gnome desktop on my remote server. So, you install one or two X11 packages (Xauth?) on the remote server, and allow the DBA to run the Oracle installer remotely using something simple like 'ssh -X /media/cdrom/oracle-installer'.

3

There is also a security advantage when using VNC or NX (X2Go). A malicious app cannot take screenshots or use a keylogger to log keys of your real desktop, while it is possible using SSH with X11 forwarding even if the malicious app runs in background.

If you use SSH -X (or -Y), you should trust the app (e.g. open source app that comes from an official Linux distribution package) or avoid doing sensitive work while running it.

I was able to verify this with these cross-platform and open source tools (tested in an LXC container):

https://github.com/lxqt/screengrab

https://github.com/GiacomoLaw/Keylogger

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .