| Enable remote desktop on linux using VNC |
Introduction
As an Windows administrator, I always have to work with many Windows servers. Most of the time, I use remote access rather than go to in front of each server. This can be done easily because they’re the same platform. But sometime I also need to access Linux server from Windows XP, too. This can be done by using VNC. By default, VNC is alrealy installed on Redhat so I only need to configure it as VNC server and I have to install VNC Viewer on Windows XP. When enable this service, please keep in my that others can also remote to the server with this protocol, too!. So if your network can’t be trusted, do not enable the vncserver service. But in my case, I have firewall to limit only from my computer and the network is trusted.
VNC stands for Virtual Network Computing. It is remote support software which allows you to view and fully interact with one computer desktop (the “VNC server”) using a simple program (the “VNC viewer”) on another computer desktop anywhere on the Internet. The two computers don’t even have to be the same type, so for example you can use VNC to view a Windows Vista desktop at the office on a Linux or Mac computer at home. For ultimate simplicity, there is even a Java viewer, so that any desktop can be controlled remotely from within a browser without having to install software.
Step-by-step
In this section, I’ll show how to configure VNC server on Redhat server and using VNC Viewer connect the server remotely from Windows XP.
- On Redhat server, login with your username that you want to enable remote access. In this example, I will use ‘admin’ user.

- Open Terminal, type ‘vncpasswd’. Type your password and verify password again. This command will use to set you password for remote access for the current user.

- Before next step, you need to logged on as root by type ’su root’.

- Edit the file /etc/sysconfig/vncservers by type ‘ vi /etc/sysconfig/vncservers’.
Note: If you are new to Linux, vi is an editor tool in command line mode on Linux.

- You’ll see text file as in the figure below. Next, I’ll edit on the highlight line.

- Uncomment on the highlight line. If you have more than one usernames that want to enable remote acces, you can change VNCSERVERS value in this format, “1:username1 2:username2 3:username3 ….”. In this example, I have only one user which is root so this line of mine is ‘VNCSERVERS = “1:admin”‘.

- Now save the file and exit. To save file, hold ESC + ‘:’ and type ‘wq’ to write and quit file.

- Next, log off the user if you are not user ‘root’ and log in as root. Enable VNC service by type ‘chkconfig vncserver on’. Then, start the VNC service by type ’service vncserver start’.

- If you have firewall enable on Redhat, be sure that your firewall configuration won’t block connection from remote computer by open port TCP 5901 for remote access. Open Applications -> System Settings -> Security Level. Add ‘5901:tcp’ on Other ports.
Note: VNC uses TCP protocol on port 5901.

- Now you can connect Redhat server from remote computer. On my Windows XP computer, open VNC Viewer on Windows XP, type IP Address of Redhat server with number as a username specify in step 6. In this example, I want to remote to Redhat server as ‘admin’ user which I assign as number 1 in step 6 (1:admin) and my Redhat server is 10.110.141.220. So I type ‘10.110.141.220:1′.
Note: You can download VNC Viewer for free at realvnc.com

- Type your password for ‘admin’ user which has been assign in step 2.

- Now you have connect to Redhat server remotely. But you’ll see that the interface looks different. You have to do a little thing more.

- On Redhat server, open terminal and type ‘vi /home/username/.vnc/xstartup’. In this example, I type ‘vi /home/admin/.vnc/xstartup’.
Note: If you going to enable remote access for user ‘root’, the file would be at ‘/root/.vnc/xstartup’.

- Uncomment these two lines and save the file.
Note: If you want to force to load Gnome or KDE Desktop on remote access, edit the last line from ‘twm &’ to ’startx &’ for Gnome and ’startkde &’ for KDE Desktop.

- Type ’service vncserver restart’ to apply changes.

- Reconnect using VNC viewer on remote computer again. Now you will see the desktop as you were log in at the server but now you’re remotely :).


























April 6th, 2008 at 12:18 am
very good help but i have a smll issue i m not able see .vnc/xstartup in /home/admin folder
due to this i am not getting exact desktop of linux in window XP system need your help on this
April 8th, 2008 at 4:25 pm
What user you have configured vnc to login as?
If you want to vnc to Linux as root, the path will be ‘/root/.vnc/xstartup’.
Otherwise, the path will be ‘/home/username/.vnc/xstartup’ which username is the user you want to configure.
April 22nd, 2008 at 1:02 pm
[...] (http://www.linglom.com/2008/02/11/enable-remote-desktop-on-linux-using-vnc/) [...]
May 22nd, 2008 at 3:18 pm
Hi,
This was of a great help to me!!
But, I have a small problem. whenever I try to connect to Linux, it is going to Root’s desktop. I have created another user called “TestUser” in the Linux machine other than Root. TestUser is a normal user and not admin to the Linux machine. I want to connect to the desktop of Testuser doing the RDP using VNC viewer. How can I do it?
May 23rd, 2008 at 10:38 am
You can add new terminal for another user by modify code in step 6. Modify to VNCSERVERS = “1:admin 2:TestUser”
Next, set VNC’s password for TestUser as in step 3.
Then, you can access to TestUser’s desktop using vnc by type “10.110.141.220:2″.
May 28th, 2008 at 5:42 am
I get up to the part where you have to run “vi /etc/sysconfig/vncservers” then it tell me it does not exist. If I make it create one, I have a blank doc to edit. What did I miss?
May 28th, 2008 at 9:09 am
You should verify that vnc-server package has been installed on the Linux. If you’re using Red Hat Enterprise 4, click Applications -> System Settings -> Add/Remove Applications. Click details on X Windows System -> browse to extra packages and verify that vnc-server package is already installed.
Also, to edit this file, you need to login as root.
May 28th, 2008 at 9:17 am
I am logged in as root and vnc-server package is running. However, I am running Red Hat 9 (shrike), if that makes any difference.
June 21st, 2008 at 4:58 am
I am having the following error. Its RedHat Linux enterprise Server 5…
Warning: localhost.localdomain:1 is taken because of /tmp/.X1-lock
Remove this file if there is no X server localhost.localdomain:1
A VNC server is already running as :1
June 21st, 2008 at 1:32 pm
Try to remove that file by run this command:
rm -f /tmp/.X1-lock
June 23rd, 2008 at 8:27 pm
Thanks Alot .. It worked .. It gave me another file Lock error but I deleted that one also with your given format and its connected now.
You are the Man ..
Again .. Thanks Alot
June 26th, 2008 at 2:21 pm
I have VNC up and running but when I connect as a non-root user I can not see any text, the icons show fine and but no text.
Please help me out….
July 8th, 2008 at 9:02 am
Hi, Orane.
Sorry for late reply. Try to restart the Linux server and vnc to the server again.
July 12th, 2008 at 7:48 am
great post!
but somehow even if I change the last line in file xstartup to startx &, vnc somehow still show the KDE interface instead of GNOME,
Any idea where I should look to fix this? thanks!
July 13th, 2008 at 11:56 am
To Gary,
Actually I’m not expert in Linux but I suggest that you check that GNOME desktop has installed on the system already or not. Next, try to change default desktop to GNOME to see that GNOME desktop can load properly. You can search on Google how to achieve this.
July 29th, 2008 at 8:20 pm
Dear Linglom,
Thanks for your vnc setup from windows machine on linux (user name) . I have one problem we got desktop of username but not perfactly seen this desktop means all incons exact as username not seen. Our windows machine is Windows -vista and red hat 9.
What can I do for it ?
Regards
Vipul Patel
Ahmedabad
India
July 31st, 2008 at 10:18 pm
Hello, Vipul Patel
I couldn’t imagine what you have seen the desktop. Maybe you could upload the screen-shot on my forum.
August 12th, 2008 at 10:10 pm
Does this work on Fedora Core 9? I followed all the steps and I see a black clothlike screen when I remote into my Fedora Core 9 box. What should I do to fix this?
August 14th, 2008 at 9:24 pm
It should works. Try to restart the server that you’re going to remote to.
Otherwise, it’s better to post your problem on Fedora Forum.
August 29th, 2008 at 1:59 pm
Reply to comments 12 and 13 above about NON Root user.
I also had a problem with a non-root user. The popup menus didn’t quite work, and although I would see the hourglass for starting other programs, their window would never come up.
But doing a full Linux reboot DID fix the problem.
Some other minor things on my system (Cent OS 5)
Step # 7 and comment 4:
I had to have:
VNCSERVERS = “1:root 2:mbennett”
On my system it’s root, not admin, and then my username is mbennett on display # 2.
Also, I was getting a failure on the vncserver restart.
I copied the fixed up /root/.vnc/xstartup to /tmp
Then logged in as mbennett and copied /tmp/xstartup to /home/mbennett/.vnc/xstartup (had to mkdir .vnc directory)
Also, in Step # 9 to allow the firewall, in Cent OS 5, it’s slightly different:
System -> Administration -> Security Level and Firewall
Still struggling with the machine changing IP address after every reboot and not registering it’s name with the router, but at least the displays now work with me needing a console login.
OTHER web sites had said to add port 5900 to your firewall and goto :0. THAT’s why I had to manually login, to start that xserver. But with the extra instructions in this blog’s main article, you are starting extra services when the machine first boots, so it doesn’t wait for a manual console login.
THANK YOU for all the great instructions!!!!!!!
September 9th, 2008 at 10:53 pm
Hi,
Thanx for u step by step process. i havea query i am unable to get the exact desktop(teminal) what exactly running on linux machine.how can i get this.
September 9th, 2008 at 10:54 pm
Hi,
I am using fedora core 5 with kde desktop.
September 14th, 2008 at 11:27 am
Hi, raj
Have you ensure that you’ve specified correctly username index on VNC Viewer when connect ? (IP Address:user_index)
September 15th, 2008 at 11:19 am
Yes everything is absolutly correct my requirment is iam able to see 192.168.1.92:1 which is new terminal but i want the live terminal . i mean the running terminal on that in system my system i am using KDE desktop
September 15th, 2008 at 3:38 pm
Hi, raj
I understand your problem now. You want to vnc to the server as same session as in front of the server. I have tried to do that but it won’t work.
Sorry, I couldn’t help you.
September 24th, 2008 at 4:28 pm
“Note: If you are new to Linux, vi is an editor tool in command line mode on Linux”
Haha this is too funny. If you are new to Linux the last thing you will want to use is an uncomprehensible, unintuitive garbage editor like vi. It’s like using something from 1960. Surely there is SOMETHING better to use, no?
September 24th, 2008 at 4:31 pm
Oh and what the hell is WRONG with logging into the same session? It’s a total piece of cake in windows but whatever I try in Linux it seems damn impossible. What’s that all about? Surely it can do this but nobody ever has an answer… which leads me to believe it cannot. Honestly, it’s 2008 ffs, it’s about time things like this (and total crap vi editor) were sorted out/upgraded/etc. etc.
And they pretend linux is a threat to windows. Dream on.
October 3rd, 2008 at 7:52 pm
Hi Guys,
My VNC Viewer Was working fine but unfortunatley during the session I Loggoff the admin (ONLY user I use to logon to VNC viewr)
Now it connects but shows me blank blank Screen. How can I log in the admin again ???
October 3rd, 2008 at 8:35 pm
Restart the PC which running VNC Server should solve the problem.
November 6th, 2008 at 11:09 am
I was do above on user root, but when runing command
[root@localhost ~]# vi /etc/sysconfig/vncservers
[root@localhost ~]# service vncserver start
Starting VNC server: 1:admin runuser: user admin does not exist
[FAILED]
please , explain for me! thanks
November 6th, 2008 at 9:55 pm
The error stated that user ‘admin’ doesn’t exist. In the example in my post, I’ve demonstrated to remote to user ‘admin’. But if you don’t have this user, the error will occur like yours.
In step 6 of my post, try to apply to your user.
November 7th, 2008 at 4:23 am
Dear all !
I need you help me!
the now , my server have two user is root and oracle is created.
I was do folowed:
[root@localhost ~]# vi /etc/ sysconfig/vncservers
on is this I was repalaced two command line above :
#VNCSERVERS = “1:root 2:oracle” by VNCSERVERS = “1:root 2:oracle”
#VNCSERVERARGS[1] = “-geometry 800×600” by VNCSERVERARGS[1] = “-geometry 800×600”
return I Wq!
step 2 :
at this : [root@localhost ~]# service vncserver start
when that it message error :
Starting VNC server: 1:root runuser: user root does not exist
[FAILED]
please , explain for me! thanks
November 7th, 2008 at 9:30 am
Can you try each user at a time to see if you can start the service?
1. VNCSERVERS = “1:root”
2. VNCSERVERS = “1:oracle”
November 10th, 2008 at 9:43 am
Dear, linglom!
I was maked as you haved explain for me and I was running as folow:
#The VNCSERVERS variable is a list of display:user pairs.
# Uncomment the line below to start a VNC server on display :1
# as my ‘myusername’ (adjust this to your own). You will also
# need to set a VNC password; run ‘man vncpasswd’ to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see
# .
VNCSERVERS=”1:root”
VNCSERVERS=”2:oracle”
VNCSERVERARGS[1]=”-geometry 800×600″
~wq
when I runing then display message error :
[root@localhost ~]# service vncserver start
Starting VNC server: 2:oracle [FAILED]
[root@localhost ~]#
please , Explain for me again!
Thanks.
November 10th, 2008 at 9:53 am
Thanks, I was return successfull
reasion is I not vncpass for each user.
November 14th, 2008 at 4:09 am
[...] Tight VNC questions? Follow-up. i followed this link’s instructions; Enable remote desktop on linux using VNC | Linglom’s Blog Everything worked until I go to here; jmariscal@ITSUSE:~> chkconfig vncserver on bash: [...]