Piss-easy linux VNC setup

I remember I used to struggle with getting VNC to work on linux. That is until the other day when I had a brainwave and then did it in no time at all. I think I was forgetting the firewall step. Anyways, I thought I’d outline how to do it here for anyone else. This is for a Fedora 8 box though you can usually find similar config files on a debian os. Also I like to use vi… most people prefer nano or pico or gedit or whatever. Just make sure you’re root when editing system files of course.

The first bit is if you haven’t got vnc install it:

sudo yum install vnc-server

Then you want to edit the config file for vnc (mine is located in /etc/sysconfig):

sudo vi /etc/sysconfig/vncservers

And in here you want to put the following (notice the number 0? Thats the viewport number):

VNCSERVERS="0:USERNAME"
VNCSERVERARGS[0]="-geometry 1024x768 -nohttpd"

So you replace USERNAME with your username (e.g. hamstar) and then connecting to viewport 0 you will be logging in as USERNAME. Then you want to type vncpasswd as user USERNAME in the command line and enter a password to connect to the vnc session.

Now I like to use gnome so in my /home/USERNAME/.vnc/xstartup at the very end I deleted the default window manager(twm &) and instead put this:

exec /usr/bin/gnome-session &

So that makes sure that when I login to VNC I am given my gnome desktop on the server. You can put KDE or whatever in there like the following if you want to use that:

exec /usr/bin/startkde &

Now the last thing to do is to poke a hole in the firewall. I have issues with this trying to modify iptables straight from the command line, so I found my iptables startup config in /etc/sysconfig too:

sudo vi /etc/sysconfig/iptables

In here I put the line:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5900 -j ACCEPT

So that opens up port 5900 on the firewall. Notice that the last digit (0) corresponds with the viewport number you put in the vncservers file. So if you had VNCSERVERS=”2:USERNAME” you would want to change 5900 to 5902.

Now we need to restart the firewall and start the vncserver:

sudo service iptables restart
sudo service vncserver start

Now from whatever box you want to connect to VNC from (in my case a windows box) start your vnc program and in the box enter the machines IP address or hostname followed by a the viewport number :0. Remember to change the number if you changed it in the vncservers config file (i.e. :2).

Then it will connect, type the password that you told vncpasswd a few steps back and you should have your server desktop infront of you.

choppaNow I know some of you gui-junkies will be whinging “aww, I have to open the command line whinge whinge fuCKing whinge,” well, Chopper says harden the fuck up. It’s just a command line, its linux for fucks sake, its faster and more efficient to use than any gui for some things. The only reason everyone uses a gui on windows is because DOS fucking sucks ass.

So I hope that makes it clear for people. If you need help, google it or post a comment.

Leave a Reply