Enable remote desktop on Linux using VNC

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.

  1. On Red Hat server, login with your username that you want to enable remote access. In this example, I will use ‘admin’ user.
    Red Hat Gnome's desktop
  2. 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.
    Set VNC password
  3. Before next step, you need to logged on as root by type ‘su root’.
    Log as root using su
  4. 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.
    Edit /etc/sysconfig/vncservers
  5. You’ll see text file as in the figure below. Next, I’ll edit on the highlight line.
    /etc/sysconfig/vncservers
  6. 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”‘.
    Edit /etc/sysconfig/vncservers
  7. Now save the file and exit.
    To save file, hold ESC + ‘:’ and type ‘wq’ to write and quit file.
    Write and quit file in vi editor
  8. 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’.
    Set up VNC server as service and start
  9. 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.
    Open TCP port 5901 for remote access
  10. 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
    Test connect to Red Hat server from remote computer
  11. Type your password for ‘admin’ user which has been assign in step 2.
    Specify password
  12. 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.
    Remote screen
  13. 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’.
    Edit /home/admin/.vnc/xstartup
  14. 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.
    Edit xstartup
  15. Type ‘service vncserver restart’ to apply changes.
    Restart VNCServer service
  16. 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 :).
    Connect to Red Hat server remotely

81 Comments

  1. Nagesh April 6, 2008
  2. linglom April 8, 2008
  3. Kishore May 22, 2008
  4. linglom May 23, 2008
  5. Taino May 28, 2008
  6. linglom May 28, 2008
  7. Taino May 28, 2008
  8. Atif June 21, 2008
  9. linglom June 21, 2008
  10. Atif June 23, 2008
  11. orane June 26, 2008
  12. linglom July 8, 2008
  13. gary July 12, 2008
  14. linglom July 13, 2008
  15. Vipul Patel July 29, 2008
  16. linglom July 31, 2008
  17. Kenny August 12, 2008
  18. linglom August 14, 2008
  19. Mark August 29, 2008
  20. raj September 9, 2008
  21. raj September 9, 2008
  22. linglom September 14, 2008
  23. raj September 15, 2008
  24. linglom September 15, 2008
  25. Geek1 September 24, 2008
  26. Geek1 September 24, 2008
  27. Atif October 3, 2008
  28. linglom October 3, 2008
  29. chi dung November 6, 2008
  30. linglom November 6, 2008
  31. chi dung November 7, 2008
  32. linglom November 7, 2008
  33. chi dung November 10, 2008
  34. chi dung November 10, 2008
  35. Pingback: Tight VNC questions? - openSUSE Forums November 14, 2008
  36. Kelvin Arcelay December 12, 2008
  37. linglom December 12, 2008
  38. Kelvin Arcelay December 13, 2008
  39. linglom December 13, 2008
  40. Kelvin Arcelay December 13, 2008
  41. linglom December 13, 2008
  42. Kelvin Arcelay December 14, 2008
  43. Sai S January 31, 2009
  44. Gulam February 18, 2009
  45. -=marky=- March 13, 2009
  46. linglom March 18, 2009
  47. -=marky=- March 20, 2009
  48. david April 24, 2009
  49. Jay May 11, 2009
  50. Jay May 11, 2009
  51. ptc July 30, 2009
  52. gaurav October 22, 2009
  53. senthil November 10, 2009
  54. Siddhu November 12, 2009
  55. Alcides Magule November 28, 2009
  56. Jcummings December 19, 2009
  57. Alessandro Ilardo January 27, 2010
  58. yasir July 8, 2010
  59. linglom July 15, 2010
  60. Yesudas August 5, 2010
  61. kamachi August 11, 2010
  62. Hugo September 22, 2010
  63. Satish September 28, 2010
  64. priya October 5, 2010
  65. sanky November 29, 2010
  66. Kamal Maiti December 29, 2010
  67. Gokul January 21, 2011
  68. Karuppu February 5, 2011
  69. Faz February 16, 2011
  70. Zaf February 17, 2011
  71. dilip September 28, 2011
  72. Edmundo Coache November 25, 2011
  73. Trinity Starbuck December 1, 2011
  74. shambhu February 20, 2012
  75. john March 11, 2012
  76. Smith March 16, 2012
  77. Pakclay April 18, 2012
  78. dave September 14, 2012
  79. Alex Hox September 27, 2012
  80. Hari February 7, 2013
  81. Santanu Das March 20, 2013
  82. Zul May 7, 2014

Leave a Reply