Grabbing a Remote User's Display with x11vnc
Let's consider a scenario. You've got a user of your software who's struggling with how to do something. You know if you were there, you could show them very quickly, but trying to explain via telephone or email is proving really difficult. Or perhaps you need to interact with a remote display for some other reason, such as running graphical software on the remote machine with the option to detach from the session with the software still running, and be able to pick it up again when you're in front of the machine. You also might have left some software or website open on your screen and decide you need to close it. All of these scenarios could be challenging to you, linux being a multi-user operating system and all. It's designed to allow multiple users access to the machine without running into each other, but what if you want to run into each other?
Enter x11vnc. This handy little peice of software allows you to create a vnc server on a machine that's attached to a real display (usually, but not always the ':0' display). You can interact with the desktop environment or even the gdm session (login screen). From the x11vnc homepage:
To get started then, you'll need to have x11vnc installed on the remote machine. You may also want to install a vncserver package (such as 'vnc4server') if you're interested in using the java appliet for access through a web browser, but we'll cover that in a little bit. You can get x11vnc from the aforementioned homepage, or it's available as a debian package named x11vnc. To run it in its simplest form, you'll want to be root on the remote machine (most likely via ssh), and use the gdm (or xdm/kdm or whichever flavor of login manager is running) xauth file for authorization. That's good throughout the X session, whichever user is logged in, and even when none are and the login manager is running. For example:
x11vnc -display :0 -auth /var/lib/gdm/\:0.Xauth
You'll get a nice long warning that you're running x11vnc WITHOUT a password, and that this is insecure. In practice, I rarely use this outside of a LAN or VPN (Virtual Private Network), so I rarely use the password feature. You could tell vnc to ask for a password using the '-passwd' or '-passwdfile' options.
Note that running this way will disconnect the first time that X blips (display manager turns over control to desktop manager or vice versa, X restarts, etc) or you disconnect from it and you'll have to restart it again before you can reconnect. That's fine for incidental or one-time tasks, but if you'd like it running constantly, you'll have to add a few arguments to the command line.
x11vnc -display :0 -auth /var/lib/gdm/\:0.Xauth -loop
This will restart the x11vnc process automatically whenever X blips or you disconnect from the vnc session. To prevent it from stopping when you disconnect, you can supply the '-forever' option. Because desktop sizes are what they are, and vnc clients don't always provide scaling options, I like to scale down the screen size that vnc serves up with the '-scale' option. Also, you will notice after a little use that x11vnc isn't always consistent with the port that it serves up a vncserver on, so I tell it where to serve this with the '-rfbport' option. so the line I use most often is usually something like
x11vnc -display :0 -auth /var/lib/gdm/\:0.Xauth -forever -loop -scale 4/5 -rfbport 5909
I might run it inside a screen session on the remote machine, and leave it running,
disconnecting and reconnecting until the project is complete, if it's short. You could also add the '-bg' option to make
x11vnc go to the background after starting, and add the line to /etc/rc.local.
A neat implementation is to call it from a script that connects, starts the x11vnc session, then starts the viewer like so:
#!/bin/bash
if test $# -lt 1; then
echo "Usage: `basename $0` <hostname/ipaddress> [extra options to x11vnc]"
exit 1
fi
host=${1};
shift;
port=`ssh -t $host "x11vnc -display :0 -bg $* 2>&1 | grep 'The VNC desktop is:'"`
vncviewer ${host##*@}:${port//[^0-9]/}
I've attached the file for your convenience. It can be run either like:
./getdesktop.sh <hostname/ipaddress>
or you can add the 'user@' to the hostname or ip and any extra options to pass along to x11vnc at the end like so:
./getdesktop.sh <user>@<host or ip> -xauth /var/lib/gdm/\:0.Xauth -scale 3/4
to add the java applet so you can browse to http://<hostname>:(rfbport+5800), you'll have to install a vncserver package, like vnc4server or tightvncserver and find where they server their java applet from. You then point x11vnc to it using '-http -httpdir /usr/share/vnc-java' for example.
Hopefully, you'll have enough here to get rolling. For more options to x11vnc (there are many more), have a
look at the x11vnc man page and the documentation on the x11vnc homepage.
Happy Hacking!
Brian
- Login or register to post comments
- 604 reads
Printer-friendly version


