Enable remote desktop on linux using VNC
As a 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 sometimes, I 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 mind 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 Red Hat server and using VNC Viewer connect the server remotely from Windows XP.
- On Red Hat 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 Red Hat, 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 Red Hat server from remote computer. On my Windows XP computer, open VNC Viewer on Windows XP, type IP Address of Red Hat server with number as a username specify in step 6. In this example, I want to remote to Red Hat server as ‘admin’ user which I assign as number 1 in step 6 (1:admin) and my Red Hat server is 10.110.141.220. So I type ‘10.110.141.220:1’.
Note: You can download VNC Viewer for free at Download VNC® Viewer
- Type your password for ‘admin’ user which has been assign in step 2.
- Now you have connect to Red Hat server remotely. But you’ll see that the interface looks different. You have to do a little thing more.
- On Red Hat 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 :).
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
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.
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?
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”.
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?
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.
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.
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
Try to remove that file by run this command:
rm -f /tmp/.X1-lock
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
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….
Hi, Orane.
Sorry for late reply. Try to restart the Linux server and vnc to the server again.
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!
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.
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
Hello, Vipul Patel
I couldn’t imagine what you have seen the desktop. Maybe you could upload the screen-shot on my forum.
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?
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.
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!!!!!!!
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.
Hi,
I am using fedora core 5 with kde desktop.
Hi, raj
Have you ensure that you’ve specified correctly username index on VNC Viewer when connect ? (IP Address:user_index)
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
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.
“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?
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.
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 ???
Restart the PC which running VNC Server should solve the problem.
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
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.
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
Can you try each user at a time to see if you can start the service?
1. VNCSERVERS = “1:root”
2. VNCSERVERS = “1:oracle”
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.
Thanks, I was return successfull
reasion is I not vncpass for each user.
Hello,
I have two question:
1) I can not find the .vnc/xstartup in /home/username directories.
2) I am able to connect to the desktop if I am locally logged on to the server. Is there a way to make it way w/o having to signon locally?
Hi Kelvin,
1. Did you use Redhat? Redhat should have vnc built-in already. If you use other Linux, it may need to configure differently. Otherwise, try to re-install vnc.
2. If vnc works properly, you can remote to the server without logon locally. I think may be something wrong on your configuration. Have you already enabled vnc service by execute ‘chkconfig vncserver on’?
Hi, I am using Fedora 9 and the chkconfig does not work form the command line. The easiest way is to use the UI to work with the service applet.
Thanks
The steps for Fedora should be the same as in the post above. So by using UI, did you configure it successfully?
I did some more research online that helped me locate the /.vnc/xstarup. And, after I uncommented the following 2 lines:
unset SESSION_MANAGER
exec /etc/X11/xinitrc/xinitrc
re-started the service, it worked.
Great, could share on this blog where is your “/.vnc/xstarup”?
Yes, it was where you suggested however it is hidden…you can not see it but executing the cd to it will take you there.
Excellent article. Worked exactly…
Thanks,
Sai
Dear Sir,
i like your all articals and helped me a lot
you have any post on ‘how to take linux system backup’ like in windows systemstate.
thanks….:)
Regards, Rasool
hello there!
how to make my remote VNCviewer and my Vncserver display be thesame because when I configured my vncserver on my RedHat 4 and a Linux OS server its gives me this IP and Port number 192.168.0.50:1 base on my server IP Address to used when I remote my Server from my desktop windows XP using VNCviewer but I wonder why there is an extension (:1) after on my IP….?and when I try to remote my server I need to type 192.168.0.50:1 and the viewer showns different from my Server display? how to configure this thing so that I can make the same display on my remote viewer display and to my server display.?
Hi, Marky
From the post above on step 6, you can assign the extension (:1,:2, etc.) to account that you want if you want to remote more than one account.
About same desktop on both remote and local, I’m not sure about that but I think you can’t do that because VNC always creates new desktop, directory for users.
hi, linglom
thanks for the reply, but I wanted to make same desktop on both my remote and local but I dont know how and where to be configure in order to make it…but I’m sure its possible because our company had 3 servers and the previous company technician configured the VNC server to view as same desktop on both remote and local…and he didn’t teach us on how to configure it until he left on this company…
any else had any idea on how to make the same view on my remote and local desktop?because when I connect from remote computer to new server I always used an extension port like (:1) exam: 192.168.0.50:1
Got everything working fine except, is it possible to take over a currently running session that someone has started on console.
Hi,
This was a nice post. I learned a new way to setup VNC.
I just have a query in here.
In RHEL 4 AS, the default value of /etc/sysconfig/vncservers VNCSERVERS=”1:myusername” .
In RHEL 5.3, VNCSERVERS=”2:myusername:”
I notice the difference in port there. (1 and 2)
I made experiment in RHEL 5.3 by putting these values: VNCSERVERS=”1:root 2:anotheruser”
When I restarted the service, It FAILED.
Error message is ” A VNC server is already running as :1 ”
But I have no vncserver running that time.
I changed it to VNCSERVERS=”3:root 2:anotheruser (in RHEL5.3)
I restart the service, it Ok.
I can connect to root user using port :3
I was expecting, before I did this experiment, that the port :1 was reserved to root.
because of this value VNCSERVERS=”2:myusername”
But it failed when I use this: VNCSERVERS=”1:root 2:anotheruser”.
If not the root, who owns port :1 then?
Appreciate your help
Marky:
“but I’m sure its possible because our company had 3 servers and the previous company technician configured the VNC server to view as same desktop on both remote and local”
You could configure remote desktop instead.
Nice and clean step by step guide to avoid all possible pitfalls one may encounter while doing this vnc setup; it really saved me a lot of time that otherwise I’d have to spend figuring these details out on my own. Thanks a bunch!
Really nice explanation. Atleast it worked for me!!!!
its very very helpful post for me
The article and very helpful, Thanks a lot
This is the error I get after installing VNC on Fedora 11.
Help.
[root@squid ~]# vncserver
xauth: (stdin):1: bad display name “squid.localdomain:3” in “add” command
New ‘squid.localdomain:3 (root)’ desktop is squid.localdomain:3
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/squid.localdomain:3.log
[root@squid ~]#
Nice work – just a linux noob trying to get a long at the CLI, with a little hel from the gui.
This was a HUGE help and dead simple – Thank YOU
Thanks for your article. very well done, I’m going add this link to my wiki.
hi all;
This is a great help but when i try to start vncserver service it fails.
rpm is also installed
vnc-4.1.2-14.el5_3.1
vnc-server-4.1.2-14.el5_3.1
I have also checked log that shows no entry related to vnc.
what can be the problem?
Hi, Yasir
Have you configured it as shown on this post?
Hi Linglom,
Thanks for this, this will great help, but there is small issue the firewall goes down in the server and if the KDE is not installed then we are not getting the GUI
kindly help
Thanks a lot for this post.. This article is in my bookmarks now..
Hi,
Very good article. I run RedHat 5.4 and it works for me. But only if a user has already logged on at the remote server.
Then someone need to login at the remote server, before I can access remotely using VNC viewer.
Such is not handy, in case the remote server gets rebooted.
What should be done/changed to access the remote server after a reboot?
Thanks in advance,
great stuff! thanks!!
hi,
vi /etc/sysconfig/vncservers
after uncommenting this line and adding 1:root
VNCSERVERS=”1:root”
bash-3.1# chkconfig vncserver on
bash: chkconfig: command not found
bash-3.1# service vncserver start
bash: service: command not found
am getting this.
please help
thnx alot for this post;can we access same system at two different place?????????
Excellent article 🙂
I was wondering how to do this.. Ur article helped me do that..
Thanks a lot!
I was very because Ur article helped me solved this issus.
Thanks for the useful info.
Have followed this simple to follow instructions on Oracle Linux 5 and worked perfect.
Now, I’m gonna try and install oracle 🙂
Thank you
Hi Linglom,
Fantastic post! i have one question-
when i connect as root using vnc Viwer, i see everything on desktop as expected, howevwer, when i logoff from within RedHat linux server (while in remote session) i then see a balnk red screen?
If i close the VNC session and try to connect again i put my password and it logs in but its like it still has the last session so i still see blank Red screen?
Workaround for me is to restart vncserver service on RedHat server and then when i connect using vnc viewer again i see everything as expected?
any ideas?
Hi Linglom,
i did all the steps but after login through vnc i am getting only blank screen. I tried to change the xstartup file but it says this file can not be modified in this environment, display not set. kindly help me out with this
Straight to the point and well written! Why can?t everyone else be like
My friendrecommended I might like this blog. He was totally right. This post actually made my day. You cann’t imagine simply how much time I had spent for this information! Thanks!
dear sir/madm,
please help me how to connect two computer
first computer redhat entetprise linux 6
second computer window 7
from remote desktop
i use rhel 6……
your instructions are extremely wonderful. I followed exactly, and got everything worked right then, was able to connect from my Windows 2008R2 64bit server to RH. Thanks bro.
I did follow up the steps but my VPS showed that there are no such repositories 🙁 what to do now ?
I searched more on Google and found this. I have two VPS. One is a fresh VPS and on other I have websites.
I did what is written here: http://www.l337fx.com/installing-remote-desktop-rdp-centos-vps.html and it was successful. But I wanna know if I can do it on the VPS which I have websites.
Thanks a lot..
Well. Followed all the steps to a “T”. only problem is (checking my ip address 10 times) i still cannot connect. I think it might be because my internet provider blocks the ports 5900-6000. What might i do. And no they will not open that port. Something about spam????
Hi
I have RHEL5 OS. In GUI on GMONE, built-in RDP VNC running, configured perfectly and work well, but after reboot i can’t login to system.
IÑм followed the instruction, but service vncserver not found. However when I type command “vncserver: 1-geometry 800×600-depth 16” it’s work without error
Great post… thanks.. 🙂
multiple user cant access vnc server,how will i add miltiple users,above post is not support that…….
Hi Linglom,
I have same problem with Atif and Zaf as their questions above…
The screen show nothing(blank) after I log off from RedHat…
Hope you can help me…