Skip to main content

Setup VNC Server in Linux


This is how-to on setting up a VNC server on a Linux machine. 

Many times I've feel the need to VNC into the server & do the tasks. This is incredibly easy & can be done within few steps. We'll be setting up unencrypted VNC.

Step 1: Installing Packages

There are a just a couple of packages to be dealt with. Those packages can be installed with a single command. Before you run the command, you must first "su" to root. This is done by entering the command su and then typing your root user password. Once you have root access, run the command:

yum install vnc vnc-server

Once the above command completes, you are ready to begin the configuration.


Step 2: Configure Users



I will assume you already have either the users that will be allowed to VNC into the machine, or you only have one user that will be gaining access to the machine. Either way, the users will already have accounts on the server and will have logged in to confirm their passwords/accounts.
For each user that needs to gain access to the VNC server, you must set a VNC password for them. Let's say you've set up a user account called myvncuser and intend on logging in with only that user. To set the VNC password for the user, you must first su to that user account. Issue the command:
su myvncuser
Now issue the command:
vncpasswd
You will then be prompted to enter (and confirm) the new password for the user. Once you've completed that action, you are done with user configuration.
Step 3: Configure VNC
Now for the important pieces.The first phase of this step is to edit the /etc/sysconfig/vncservers file. At the end of that file, enter the following:
VNCSERVERS="1:myvncuser"
VNCSERVERARGS[1]="-geometry 1600x1200"
NOTE: You can set the geometry to whatever resolution you require.
In the above section, you can set up multiple users for connection. Say you had three users that needed access using different resolutions. To accomplish this, you could enter something like:
VNCSERVERS="1:myvncuser1 2:myvncuser2 3:myvncuser3"
VNCSERVERARGS[1]="-geometry 1600x1200"
VNCSERVERARGS[2]="-geometry 800x600"
VNCSERVERARGS[3]="-geometry 640x480"
Step 4: Service Startup
Before you go any further, make sure the VNC server will start and stop cleanly. As the root user, issue the commands:
  • service vncserver start
  • service vncserver stop
If the VNC server started and stopped cleanly, set VNC up to start at boot with the command:
chkconfig vncserver on
Step 5: Create xstartup scripts
You now need to go into each user that will be logging in with VNC and editing their~/.vnc/xstartup script. Within that script, you should find the following:
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
Uncomment the following two lines (remove the "#" characters):
  • unset SESSION_MANAGER
  • exec /etc/X11/xinit/xinitrc
Save that file and you're ready to move on.
Step 6: Edit Iptables
In order for the VNC connections to get through, you must allow them with iptables. To do this, open up the file /etc/sysconfig/iptables and add the line:
-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 5901:5903,6001:6003 -j ACCEPT
Save the file and restart iptables with the command:
service iptables restart
Step 7: Start the VNC server
Issue the command:
service vncserver start
And the VNC server should start up nice and cleanly.
Step 8: Test the connection
Move over to a machine that can display graphics (if your server does, you can test from there) and fire up your VNC client of choice and attempt to log in with the IP address of the server and port 5801.
There you go! You should now have a working VNC server on your Linux box

Comments

Popular posts from this blog

CentOS / Redhat : Configure CentOS as a Software Router with two interfaces

Linux can be easily configured to share an internet connection using iptables. All you need to have is, two network interface cards as follows: a) Your internal (LAN) network connected via eth0 with static ip address 192.168.0.1 b) Your external WAN) network is connected via eth1 with static ip address 10.10.10.1  ( public IP provided by ISP ) Please note that interface eth1 may have public IP address or IP assigned by ISP. eth1 may be connected to a dedicated DSL / ADSL / WAN / Cable router: Step # 1: Enable Packet Forwarding Login as the root user. Open /etc/sysctl.conf file # vi /etc/sysctl.conf Add the following line to enable packet forwarding for IPv4: net.ipv4.conf.default.forwarding=1 Save and close the file. Restart networking: # service network restart Step # 2: Enable IP masquerading In Linux networking, Network Address Translation (NAT) or Network Masquerading (IP Masquerading) is a technique of transceivin

Virtual Box and Alt/Tab Keys

I use virtual box for all my testing activities. It comes too often that I have a virtual box VM window open & I want to switch to my host machine to see some stuff like tutorials etc.. If you press the alt+tab combination it just works inside the VM & doesn't switches to host machine. In these scenarios you can press the host key once ( not hold it ) & then whatever you press goes to host machine. So in general where host key is the default Right Ctrl, just press Right Ctrl once & now press the alt+tab & it will switch you out to host machine. This is really helpful when you have the VM windows open or you're working on seamless mode. Hope it help others too.

AMD Radeon™ HD 7670M on Ubuntu 12.04

Update:   Recently I install kubuntu 13.10 and there is no problem with graphics. It just works  fine out of the box. I've seen many blog posts on how to make AMD HD7670M work on Ubuntu 12.04, specially when its in switchable graphics board like Dell Inspiron 15R 5520. I tried many things to make it work so that I could use the cinnamon desktop on ubuntu & other things too.. But to my surprise even the drivers from AMD site didn't work. Then I tried a combination of those blog posts I read & somehow I became successful in running the full graphics including compiz settings inside My Ubuntu Machine. Following are the steps I followed & it worked... 1. Create a backup of your xorg configuration file: sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.BAK 2. Remove/purge current fglrx and fglrx-amdcccle : sudo apt-get remove --purge fglrx* 3. Install the driver: sudo apt-get install fglrx fglrx-amdcccle 4. Install additional