We talked last week about how to use VNC with a server that doesn’t have a monitor connected to it.
This week, I’m going to talk about how to get around the fact that you have to be logged into Gnome in order to use VNC.
One of the nice things about using Windows is that you can now RDP to a machine that hasn’t been logged into a Windows session. This is a relatively new feature and, frankly, something I had been craving for a long time. Linux, and specifically Ubuntu, doesn’t have this feature. In order to use VNC (the Linux version of remote desktop), you must first log into an X session with the desired account. But how are you supposed to do this after an accidental reboot at a remote location? Here are your choices:
- You can have the machine automatically log into a user account and then have the screensaver lock fairly quickly. This is inherently insecure as anyone who has permission to reboot or has physical access to the machine or its power supply will be able to log in as the user without a password.
- You can manually boot the machine and then log in as the user while you’re on site. But what happens at the next power outage? Or what if you forget to log in? If it’s a remote location, you’re in for a drive.
- You can beg someone who’s at the remote location to log into the VNC server for you. This really doesn’t need an explanation as to why it’s tremendously insecure.
- You can learn to manipulate Gnome Desktop at the command line and start VNC at your beck and call.
The third answer was the best for my particular situation. Keep in mind, though, that this solution requires root access and a restart of the X server. So if this machine’s X is used by multiple parties or you don’t have the right permissions, this might not be the solution for you. Here’s how to do it in Ubuntu.
Login to the machine using SSH:
ssh user@machine
Use your favorite editor to edit /etc/gdm/custom.conf. If you’re unsure of what you’re doing, be sure to make a backup copy first!
sudo cp /etc/gdm/custom.conf /etc/gdm/custom.conf.20100611
sudo vi /etc/gdm/custom.conf
Make the following changes and substitute your login account for username:
AutomaticLoginEnable=true
AutomaticLogin=username
Restart Gnome Desktop. Warning! All of the Gnome/X sessions on the machine will end!
sudo /etc/init.d/gdm restart
Wait a few moments for the X session to start and follow the instructions in my last post to start a VNC server. Then use a VNC viewer to see your freshly logged in Gnome Desktop. Of course, you should immediately re-edit /etc/gdm/custom.conf and turn off automatic login:
AutomaticLoginEnable=false
You don’t need to restart the X server right now… you’re already logged in, right? There’s no risk of someone else somehow taking advantage. But if there’s another power outage or if someone else reboots the box, your user account won’t be automatically logged in without your knowledge.
That’s it! Enjoy this one… it is one of my favorite tricks. But what happens if you have a firewall blocking port 5900 and you only have SSH access to the machine? Don’t worry — using SSH port forwarding you can still access the VNC server. But we’ll leave that trick to another day.
