{"id":66,"date":"2012-12-30T21:45:00","date_gmt":"2012-12-30T21:45:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2012\/12\/30\/installing-vnc-server-on-centos\/"},"modified":"2021-02-22T01:26:44","modified_gmt":"2021-02-22T01:26:44","slug":"installing-vnc-server-on-centos","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2012\/12\/installing-vnc-server-on-centos.html","title":{"rendered":"Installing VNC Server on CentOS"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><img decoding=\"async\" title=\"VNC Logo\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/vnc-logo.png\" alt=\"Virtual Network Computing Logo\" border=\"0\" \/><\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">What is VNC?<\/h2>\n<div style=\"text-align: justify;\">VNC (Virtual Network Computing) is a graphical desktop sharing system that is used to remotely control another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical screen updates back in the other direction, over a network.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">VNC is platform-independent. That is a windows user may connect to a linux server or vice versa. Multiple users using different operating systems can connect to the same VNC server at the same exact time.<\/div>\n<div style=\"text-align: justify;\">Using VNC you can remotely control your home computer from work or vice versa.<\/div>\n<div style=\"text-align: justify;\">You may also remotely control your webserver as long as you have root access to it (usually VPS and Dedicated servers).<\/div>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Requirements for this Tutorial:<\/h2>\n<ul style=\"text-align: left;\">\n<li style=\"text-align: justify;\">Linux CentOS Server<\/li>\n<li style=\"text-align: justify;\">Windows Client.<\/li>\n<li style=\"text-align: justify;\">In this tutorial I will connect from my windows operating system to my linux server using VNC.<\/li>\n<li style=\"text-align: justify;\">To be able to successfully install and run VNC you need to have root access to your server.<\/li>\n<li style=\"text-align: justify;\">In this tutorial I&#8217;m assuming you are using CentOS operating system. Although installing it on a different Linux operating should be very similar.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Installing VNC Server on CentOS<\/h2>\n<p><span style=\"color: blue;\">First we need to install <b>X Window System<\/b> (X11)<\/span> which is a software system and network protocol that provides a basis for graphical user interfaces.<\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><b><span style=\"color: white;\">yum groupinstall &#8220;X Window System&#8221;<\/span><\/b><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"color: blue;\">Then we install the <b>GNOME Desktop Environment<\/b><\/span>, which is a desktop environment and graphical user interface that runs on top of a computer operating system and was developed mainly by Red Hat employees.<\/div>\n<p>For CentOS 5, run the following command:<\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><b><span style=\"color: white;\">yum groupinstall &#8220;GNOME Desktop Environment&#8221;<\/span><\/b><\/p><\/blockquote>\n<p>For CentOS 6, run the following command:<\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>yum groupinstall desktop<\/b><\/span><\/p><\/blockquote>\n<p><span style=\"color: blue;\">Now let&#8217;s install the VNC Server:<\/span><br \/>\nFor CentOS 5<\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>yum install vnc-server<\/b><\/span><\/p><\/blockquote>\n<p>For CentOS 6<\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>yum install tigervnc-server<\/b><\/span><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"color: blue;\">And let&#8217;s install some <b>fonts<\/b><\/span> (You may skip this step, but later on if you remotely login and you&#8217;re unable to view the remote desktop&#8217;s icons and text, you will have to install some fonts)<\/div>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>yum install xorg-x11-fonts-Type1<\/b><\/span><\/p><\/blockquote>\n<p>or<\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>yum groupinstall fonts<\/b><\/span><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\"><span style=\"font-size: large;\">Configuring VNC Server for root access:<\/span><\/h2>\n<p>To login to the remote server as root:<\/p>\n<p><span style=\"color: blue;\">Edit the <b>\/etc\/sysconfig\/vncservers<\/b> file: <\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>vi \/etc\/sysconfig\/vncservers<\/b><\/span><\/p><\/blockquote>\n<p><span style=\"color: blue;\">Uncomment the following two lines and remove <b>-nolisten tcp -localhost<\/b>:<\/span><\/p>\n<blockquote style=\"background-color: silver; padding: 5px;\"><p># VNCSERVERS=&#8221;2:myusername&#8221;<br \/>\n# VNCSERVERARGS[2]=&#8221;-geometry 800&#215;600 -nolisten tcp -localhost&#8221;<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">Where <b>2<\/b> is the port number and the <b>myusername<\/b> is the linux user.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">To login as the root with a 800&#215;600 resolution, we change the username to root and the arguments of the port as follow:<\/div>\n<blockquote style=\"background-color: silver; padding: 5px;\"><p>VNCSERVERS=&#8221;2:root&#8221;<br \/>\nVNCSERVERARGS[2]=&#8221;-geometry 800&#215;600&#8243;<\/p><\/blockquote>\n<p>Save (<b>:w<\/b>) and quit editing the file (<b>:q<\/b>)<\/p>\n<div style=\"text-align: justify;\"><span style=\"color: blue;\">Create a <b>password<\/b> for VNC root user<\/span> using the following command, you can use the same command to change your password later:<\/div>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>vncpasswd<\/b><\/span><\/p><\/blockquote>\n<p><span style=\"color: blue;\">Start the VNC Server:<\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>service vncserver start<\/b><\/span><\/p><\/blockquote>\n<p>After starting the server, a new file will be created <b>\/root\/.vnc\/xstartup<\/b><\/p>\n<p><span style=\"color: blue;\">If you are using CentOS 5, edit <b>\/root\/.vnc\/xstartup<\/b><\/span> <span style=\"color: red;\">(You can skip this in CentOS 6):<\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>vi \/root\/.vnc\/xstartup<\/b><\/span><\/p><\/blockquote>\n<p>And comment <b>twm &amp;<\/b> and append <b>gnome-session &amp;<\/b> as follow:<\/p>\n<blockquote style=\"background-color: silver; padding: 5px;\"><p>#twm &amp;<br \/>\ngnome-session &amp;<\/p><\/blockquote>\n<p>Save (<b>:w<\/b>) and quit editing the file (<b>:q<\/b>)<\/p>\n<p><span style=\"color: blue;\">Restart the VNC Server: <\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>service vncserver restart<\/b><\/span><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">Congratulations, your VNC server should be up and running, check the &#8220;Installing VNC Client&#8221; below to login and test your connection as root. Or if you want to login as a different user other than root, check the section below:<\/div>\n<h2 style=\"text-align: left;\"><span style=\"font-size: large;\">Configuring VNC Server for root access and another user:<\/span><\/h2>\n<p><span style=\"color: blue;\">Make sure you are logged in to the server as root:<\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>su &#8211;<\/b><\/span><\/p><\/blockquote>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\"><span style=\"color: blue;\">Create the new user(s) and set their password<\/span> (if they don&#8217;t exist yet). I will create a new user for this tutorial called <i>userone<\/i>:<\/div>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>useradd userone<br \/>\npasswd userone<\/b><\/span><\/p><\/blockquote>\n<p><span style=\"color: blue;\">Edit the <b>\/etc\/sysconfig\/vncservers<\/b> file: <\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>vi \/etc\/sysconfig\/vncservers<\/b><\/span><\/p><\/blockquote>\n<p>Uncomment the following two lines and remove <b>-nolisten tcp -localhost<\/b>:<\/p>\n<blockquote style=\"background-color: silver; padding: 5px;\"><p># VNCSERVERS=&#8221;2:myusername&#8221;<br \/>\n# VNCSERVERARGS[2]=&#8221;-geometry 800&#215;600 -nolisten tcp -localhost&#8221;<\/p><\/blockquote>\n<div style=\"text-align: justify;\">Where <b>2<\/b> is the port number and the <b>myusername<\/b> is the linux user.<\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\"><span style=\"color: #38761d;\">Please note that only the last digit of the port number is entered and the first three are implicit. For example, <b>2<\/b> defines port 5902. <b>9<\/b> indicates use of port 5909<\/span><\/div>\n<div style=\"text-align: justify;\"><\/div>\n<div style=\"text-align: justify;\">To login as the <b>root<\/b> with a 640&#215;480 resolution, we change the username to <b>root<\/b> and the arguments of the port as follow:<\/div>\n<blockquote style=\"background-color: silver; padding: 5px;\"><p>VNCSERVERS=&#8221;1:root&#8221;<br \/>\nVNCSERVERARGS[1]=&#8221;-geometry 640&#215;480&#8243;<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">To login as <b>userone<\/b> with a 800&#215;600 resolution, we add the port number and the username to VNCSERVERS and we add a new argument for the port. I will use port number <b>2<\/b> for <b>userone.<\/b><\/div>\n<blockquote style=\"background-color: silver; padding: 5px;\"><p>VNCSERVERS=&#8221;1:root 2:userone&#8221;<br \/>\nVNCSERVERARGS[1]=&#8221;-geometry 640&#215;480&#8243;<br \/>\nVNCSERVERARGS[2]=&#8221;-geometry 800&#215;600&#8243;<\/p><\/blockquote>\n<p>Save (<b>:w<\/b>) and quit editing the file (<b>:q<\/b>)<\/p>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"color: blue;\">Switch users and create a password for your VNC users<\/span> using the following command, you can use the same command to change your password later:<\/div>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>su &#8211;<br \/>\nvncpasswd<\/b><\/span><\/p>\n<p>su userone<br \/>\nvncpasswd<\/p><\/blockquote>\n<p><span style=\"color: blue;\">Login back as <b>root<\/b> and start (or restart) the VNC Server: <\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>su &#8211;<br \/>\nservice vncserver start<\/b><\/span><\/p><\/blockquote>\n<p>After starting the server, a new file for each user will be created:<br \/>\n<b>root<\/b> will have the following file created: <b>\/root\/.vnc\/xstartup<\/b><br \/>\n<b>userone<\/b> will have the following file created: <b>\/home\/userone\/.vnc\/xstartup<\/b><\/p>\n<p><span style=\"color: blue;\">If you are using CentOS 5, edit <b>\/root\/.vnc\/xstartup<\/b><\/span> <span style=\"color: red;\">(You can skip this in CentOS 6):<\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>vi \/root\/.vnc\/xstartup<\/b><\/span><\/p><\/blockquote>\n<p>And comment <b>twm &amp;<\/b> and append <b>gnome-session &amp;<\/b> as follow:<\/p>\n<blockquote style=\"background-color: silver; padding: 5px;\"><p>#twm &amp;<br \/>\ngnome-session &amp;<\/p><\/blockquote>\n<p>Save (<b>:w<\/b>) and quit editing the file (<b>:q<\/b>)<\/p>\n<p>Do the same for <b>userone<\/b>: (You can skip this in CentOS 6):<\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>su userone<br \/>\ncd<br \/>\nvi .vnc\/xstartup<\/b><\/span><\/p><\/blockquote>\n<p>And comment <b>twm &amp;<\/b> and append <b>gnome-session &amp;<\/b> as follow:<\/p>\n<blockquote style=\"background-color: silver; padding: 5px;\"><p>#twm &amp;<br \/>\ngnome-session &amp;<\/p><\/blockquote>\n<p>Save (<b>:w<\/b>) and quit editing the file (<b>:q<\/b>)<\/p>\n<p><span style=\"color: blue;\">Login back to root and Restart the VNC Server: <\/span><\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>su &#8211;<br \/>\nservice vncserver restart<\/b><\/span><\/p><\/blockquote>\n<p>Congratulations, your VNC server should be up and running, check the &#8220;Installing VNC Client&#8221; below to login and test your connection.<\/p>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Installing VNC Client<\/h2>\n<p>To connect to your server remotely, you need to download install <a href=\"http:\/\/www.realvnc.com\/download\/vnc\/\" target=\"_blank\" rel=\"nofollow noopener\">VNC Viewer<\/a>.<\/p>\n<p>Open VNC Viewer and enter your server&#8217;s ip or hostname and the port number, for example:<\/p>\n<div style=\"clear: both; text-align: center;\"><img decoding=\"async\" title=\"VNC Viewer\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/vncViewer.jpg\" alt=\"VNC Viewer\" border=\"0\" \/><\/div>\n<p>Enter the password that you have created with vncpasswd, and connect.<\/p>\n<p>You will see your server&#8217;s desktop, such as:<\/p>\n<div style=\"clear: both; text-align: center;\"><img loading=\"lazy\" decoding=\"async\" title=\"VNC Viewer Desktop\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/vncViewerDesktop.jpg\" alt=\"VNC Viewer Desktop\" width=\"560\" height=\"438\" border=\"0\" \/><\/div>\n<h2 style=\"text-align: left;\">Notes:<\/h2>\n<div style=\"text-align: justify;\">You will most probably need to disable Network Manager after you install the GUI. Network manager usually overwrite the settings of \/etc\/resolv.conf after every reboot.<\/div>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>service NetworkManager stop<br \/>\nchkconfig NetworkManager off<\/b><\/span><\/p><\/blockquote>\n<p>If you want to use a web browser to browse the internet, you can install firefox using the following command:<\/p>\n<blockquote style=\"background-color: black; padding: 5px;\"><p><span style=\"color: white;\"><b>yum install firefox<\/b><\/span><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; What is VNC? VNC (Virtual Network Computing) is a graphical desktop sharing system that is used to remotely control another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical screen updates back in the other direction, over a network. VNC is platform-independent. That is a windows [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17,6,31,7,50,2],"tags":[],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-server","category-ssh","category-vnc","category-windows"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":2,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":403,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions\/403"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}