{"id":9247,"date":"2021-06-21T20:49:58","date_gmt":"2021-06-21T17:49:58","guid":{"rendered":"https:\/\/kifarunix.com\/?p=9247"},"modified":"2024-03-18T20:33:26","modified_gmt":"2024-03-18T17:33:26","slug":"install-vnc-server-on-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-vnc-server-on-rocky-linux-8\/","title":{"rendered":"Install VNC Server on Rocky Linux 8"},"content":{"rendered":"\n<p>This guide will take you through how to install  VNC Server on Rocky Linux 8. VNC is an acronym for Virtual Network Computing. It makes it easy to share the graphical desktop of a system for remote control of the system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing VNC Server on Rocky Linux 8<\/h2>\n\n\n\n<p>In this guide, we are using <a href=\"https:\/\/tigervnc.org\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"TigerVNC (opens in a new tab)\">TigerVNC<\/a> to setup VNC Server on Rocky Linux 8. TigerVNC works in a client-server architecture with <code><strong>vncserver<\/strong><\/code> being the utility that provides access to remote desktop and <code><strong>vncviewer<\/strong><\/code> being the client used to connect to VNC server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install VNC Server<\/h3>\n\n\n\n<p>VNC server is provided by the <code>tigervnc-server<\/code> package which is available on the default Rocky Linux 8 AppStream repos. Therefore, update your system and install VNC server by running the commands below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo dnf update<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo dnf install tigervnc-server<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure VNC Server on Rocky Linux 8<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Create VNC Connection User Account<\/h4>\n\n\n\n<p>Once the installation completes, proceed to configure VNC server to define the users that are allowed to access remote desktop. <\/p>\n\n\n\n<p><strong>NOTE:<\/strong> The user must already be existing on the system.<\/p>\n\n\n\n<p>You can however create a user account for VNC logins.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>useradd janedoe<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>passwd janedoe<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"disblewaylandenablexorgcentos8\"><a href=\"#disblewaylandenablexorgcentos8\">Disable Wayland and enable Xorg display server on Rocky Linux 8<\/a><\/h4>\n\n\n\n<p>By default, Rocky Linux 8 uses <strong>Wayland s the default X server<\/strong>. For the VNC logins to work, you need to force the login screen to use <strong>Xorg<\/strong> server by uncommenting the line <code><strong>#WaylandEnable=false<\/strong><\/code>, on the <code>\/etc\/gdm\/custom.conf<\/code> configuration file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sed -i 's\/<strong>#WaylandEnable<\/strong>\/<strong>WaylandEnable<\/strong>\/' \/etc\/gdm\/custom.conf<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Reboot the System<\/h4>\n\n\n\n<p>Reboot your Rocky Linux 8 system to apply the changes.<\/p>\n\n\n\n<p><strong>Once the system boots, login as the user with which you will be using for remote VNC desktop logins,<\/strong> in this case, janedoe.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create VNC Systemd Service Unit file<\/h4>\n\n\n\n<p>Next, create a per user VNC systemd unit file under the home directory of every user you want to allow to connect to your remote desktop via VNC server.<\/p>\n\n\n\n<p>For example, if you want to configure VNC server to provide a display for user, <strong><code>janedoe<\/code><\/strong>, create the VNC systemd configuration file for this user under <code><strong>\/home\/janedoe\/.config\/systemd\/user<\/strong><\/code>.<\/p>\n\n\n\n<p>As a user in question and create the service unit directory above;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>su - janedoe<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir -p ~\/.config\/systemd\/user<\/code><\/pre>\n\n\n\n<p>Create user vnc service as follows.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\ncat > ~\/.config\/systemd\/user\/vncserver@.service << 'EOL'\n[Unit]\nDescription=Remote desktop service (VNC)\nAfter=syslog.target network.target\n\n[Service]\nType=forking\n\nExecStartPre=\/bin\/sh -c '\/usr\/bin\/vncserver -kill %i > \/dev\/null 2>&1 || :'\nExecStart=\/usr\/bin\/vncserver %i -geometry 1912x988\nExecStop=\/usr\/bin\/vncserver -kill %i\n\nRestart=on-success\nRestartSec=15\n\n[Install]\nWantedBy=default.target\nEOL\n<\/code><\/pre>\n\n\n\n<p>You can also restrict connection to the VNC server only through localhost (Loopback) interface by adding the keyword, <code>-localhost<\/code> to the <code>ExecStart<\/code> line.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ExecStart=\/usr\/bin\/vncserver -localhost %i<\/code><\/pre>\n\n\n\n<p>Then when run, it only opens connection on localhost.<\/p>\n\n\n\n<p>To create a systemd service as shown above, you can as well copy the&nbsp;<code>\/usr\/lib\/systemd\/system\/vncserver@.service<\/code>&nbsp;file to the user systemd service directory created above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp \/usr\/lib\/systemd\/user\/vncserver@.service ~\/.config\/systemd\/user<\/code><\/pre>\n\n\n\n<p>And modify it to suite your settings. For example, you can adjust <strong>the screen size geometry.<\/strong><\/p>\n\n\n\n<p>Reload systemd configurations to effect the changes made above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl --user daemon-reload<\/code><\/pre>\n\n\n\n<p><strong>NOTE: <\/strong>If you get the error, <strong>Failed to connect to bus: No such file or directory<\/strong>, then you need to set your <strong><code>XDG_RUNTIME_DIR<\/code><\/strong> environment variable properly (This is usually done automatically when you login via GUI).<\/p>\n\n\n\n<p>If you logged in via the GUI and still experience the issue, set this environment variable manually, <code>export XDG_RUNTIME_DIR=\/run\/user\/$(id -u)<\/code>, on your bashrc file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo 'export XDG_RUNTIME_DIR=\/run\/user\/$(id -u)' &gt;&gt; ~\/.bashrc\nsource ~\/.bashrc<\/code><\/pre>\n\n\n\n<p>Next,  confirm your environment variables, using <code><strong>systemctl --user show-environment<\/strong><\/code> command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>systemctl --user show-environment<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nDBUS_SESSION_BUS_ADDRESS=unix:path=\/run\/user\/1001\/bus\nDESKTOP_SESSION=gnome\nDISPLAY=:1\nGDK_BACKEND=x11\nGDMSESSION=gnome\nGDM_LANG=en_US.UTF-8\nGNOME_DESKTOP_SESSION_ID=this-is-deprecated\nHISTCONTROL=ignoredups\nHISTSIZE=1000\nHOME=\/home\/janedoe\n...\n...\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Create VNC Connection Password<\/h4>\n\n\n\n<p>Next, create the VNC password for the user whose VNC display has been configured. The password can set using the <strong><code>vncpasswd<\/code><\/strong> command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vncpasswd<\/code><\/pre>\n\n\n\n<p><strong>When prompted to set the read-only password, you can choose to not to set it<\/strong><\/p>\n\n\n\n<p>The VNC passwords are stored under <code>$HOME\/.vnc\/passwd<\/code>.<\/p>\n\n\n\n<p>Once you have set the password, logout by pressing <code>Ctrl+d<\/code> or just type <code>exit<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Running VNC Server<\/h3>\n\n\n\n<p>VNC server can be run as a normal systemd service. However, to run it, you need to assign a display number to the service. Systemd will automatically substitute the <code>%i<\/code> with the specified display number.<\/p>\n\n\n\n<p>Start and enable VNC server on a specific display number, by running run the command below.<\/p>\n\n\n\n<p><strong>NOTE<\/strong> that am running this commands as remote VNC login user, <strong>janedoe<\/strong> in this case and starting VNC server on display number 2.<\/p>\n\n\n\n<p>Ensure that the display number you are using is not being used;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo $DISPLAY<\/code><\/pre>\n\n\n\n<p>Start VNC on display number not being used currently.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl --user enable vncserver@:2 --now<\/code><\/pre>\n\n\n\n<p>To ensure the service runs persistently, even when the user logs out, enable lingering;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>loginctl enable-linger<\/code><\/pre>\n\n\n\n<p>To check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status --user vncserver@:2<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u25cf vncserver@:2.service - Remote desktop service (VNC)\n   Loaded: loaded (\/home\/janedoe\/.config\/systemd\/user\/vncserver@.service; enabled; vendor preset: enabled)\n   Active: active (running) since Mon 2021-06-21 13:29:55 EDT; 31s ago\n  Process: 4696 ExecStart=\/usr\/bin\/vncserver :2 -geometry 1912x988 (code=exited, status=0\/SUCCESS)\n  Process: 4690 ExecStartPre=\/bin\/sh -c \/usr\/bin\/vncserver -kill :2 > \/dev\/null 2>&1 || : (code=exited, status=0\/SUCCESS)\n   CGroup: \/user.slice\/user-1001.slice\/user@1001.service\/vncserver.slice\/vncserver@:2.service\n           \u251c\u25004703 \/usr\/bin\/Xvnc :2 -auth \/run\/user\/1001\/gdm\/Xauthority -desktop localhost.localdomain:2 (janedoe) -fp catalogue:\/etc\/X11\/fontpath.d -geometry 1912x988 -pn >\n           \u251c\u25004716 \/usr\/libexec\/gnome-session-binary\n           \u251c\u25004725 dbus-launch --sh-syntax --exit-with-session\n           \u251c\u25004756 \/usr\/bin\/dbus-daemon --syslog --fork --print-pid 6 --print-address 8 --session\n           \u251c\u25004768 \/usr\/bin\/VBoxClient --checkhostversion\n           \u251c\u25004770 \/usr\/bin\/VBoxClient --checkhostversion\n           \u251c\u25004804 \/usr\/libexec\/at-spi-bus-launcher\n...\n<\/code><\/pre>\n\n\n\n<p>You can as well stop the VNC server session by running;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl --user stop vncserver@:2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Allow VNC Server Access on FirewallD<\/h3>\n\n\n\n<p>VNC server listens on TCP port 590<strong>N<\/strong>. Where N is the VNC display number. This port is incremented based on the VNC display number. For example, for a display number 1, the VCN listens on port 5901.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ss -alt | grep 590<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>LISTEN   0         5                   0.0.0.0:5902              0.0.0.0:*      \nLISTEN   0         5                      [::]:5902                 [::]:*<\/code><\/pre>\n\n\n\n<p>If firewalld is running, you need to open each VNC display port. For example to open port 5902 for display 2, execute;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo firewall-cmd --add-port=5902\/tcp --permanent<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo firewall-cmd --reload<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Test VNC Server Connection<\/h3>\n\n\n\n<p>So how do you connect to your Rocky Linux 8 desktop via the VNC server? <code>vncviewer<\/code> is the commonly used VNC client for connection to remote desktops via VNC server.<\/p>\n\n\n\n<p>Install TigerVNC package on another Rocky Linux 8, which provides <code>vncviewer<\/code> utility.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install tigervnc<\/code><\/pre>\n\n\n\n<p>If you are connection from Ubuntu\/Debain, install VNC viewer client:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo apt install xtightvncviewer -y<\/code><\/pre>\n\n\n\n<p>Once the installation is done, you can test VNC server connection to your Rocky Linux 8 system from another host;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vncviewer host_IP_or_hostname:5902<\/code><\/pre>\n\n\n\n<p>Where <strong>host_IP_or_hostname<\/strong> is the resolvable hostname for my Rocky Linux 8 desktop with VNC server running. It can be an IP address.<\/p>\n\n\n\n<p>If all is well, you will be prompted to enter the VNC authentication password.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Connected to RFB server, using protocol version 3.8\nPerforming standard VNC authentication\nPassword: <strong>PASSWORD_SET_WITH_vncpasswd<\/strong><\/code><\/pre>\n\n\n\n<p>After a successful authentication, you should now land on Rocky Linux 8 desktop environment.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1912\" height=\"1014\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/06\/vnc-viewer-rocky-linux.png\" alt=\"Install VNC Server on Rocky Linux 8\" class=\"wp-image-9255\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/06\/vnc-viewer-rocky-linux.png?v=1624297539 1912w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/06\/vnc-viewer-rocky-linux-768x407.png?v=1624297539 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/06\/vnc-viewer-rocky-linux-1536x815.png?v=1624297539 1536w\" sizes=\"(max-width: 1912px) 100vw, 1912px\" \/><\/figure>\n\n\n\n<p>You have successfully connected to your remote Rocky Linux 8 desktop via VNC server and that marks the end of our guide is all on how to install  VNC Server on Rocky Linux 8.<\/p>\n\n\n\n<p>You can use a more secure way of logging into to a remote desktop via VNC using SSH by following the link below.<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/connect-to-vnc-server-via-ssh-tunnel\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Connect to VNC Server via SSH Tunnel<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Rocky Linux 8 guides<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-phpldapadmin-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install phpLDAPadmin on Rocky Linux 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-sssd-for-ldap-authentication-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure SSSD for LDAP Authentication on Rocky Linux 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-openldap-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup OpenLDAP on Rocky Linux 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/enable-powertools-repository-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Enable PowerTools Repository on Rocky Linux 8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will take you through how to install VNC Server on Rocky Linux 8. VNC is an acronym for Virtual Network Computing. It makes<\/p>\n","protected":false},"author":1,"featured_media":9251,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121],"tags":[],"class_list":["post-9247","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9247"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=9247"}],"version-history":[{"count":4,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9247\/revisions"}],"predecessor-version":[{"id":21773,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9247\/revisions\/21773"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9251"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=9247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=9247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=9247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}