Bobcares

DigitalOcean VNC Debian | Installation Tutorial

by | Aug 19, 2022

DigitalOcean VNC Debian allows using a keyboard and mouse to interact with a graphical desktop environment on a remote server. Bobcares, as part of our DigitalOcean Managed Service, guides you through the setup of a VNC server on a Debian 10 server.

DigitalOcean VNC Debian

The installation of a VNC server on a Debian 10 server and connecting to it securely through an SSH tunnel in a DigitalOcean platform ensures the VNC connection will be smooth and stable even on slower internet connections. A well-maintained VNC ace in managing files, software, and settings on a remote server easier for users who are not yet comfortable with the command line.

Prerequisites: One Debian 10 server setup including a non-root user with sudo access and a firewall, A local computer with a VNC client installed that supports VNC connections over SSH tunnels.

Installing The Desktop Environment And VNC Server

Debian 10 servers do not come with a graphical desktop environment or a VNC server installed, so let’s start by the installation. The following steps help us to install VNC on Debian.

  1. Firstly, update the list of packages on the server using the following command.
    sudo apt update
  2. Then install the Xfce desktop environment on the server with the below command. During the installation, we have to select the keyboard layout. Choose the appropriate one, then press Enter. The installation process will go on.
    sudo apt install xfce4 xfce4-goodies
  3. After the installation completes, now install the TightVNC server using the command.
    sudo apt install tightvncserver
  4. Use the vncserver command to set up a secure password and create the initial configuration files in order to complete the VNC server’s initial configuration after installation.
    vncserver
  5. Now we have to enter and verify a password to access the machine remotely.
    Output
    You will require a password to access your desktops.
    
    Password:
    Verify:
  6. Finally, after verifying the password, there is an option to create a view-only password. Users who sign in using the view-only password won’t be able to use their keyboard or mouse to manage the VNC instance. This is a helpful option to demonstrate something to other people using the VNC server, but this is optional.
    Would you like to enter a view-only password (y/n)? n
    xauth:  file /home/username/.Xauthority does not exist
    
    New 'X' desktop is your_hostname:1
    
    Creating default startup script /home/username/.vnc/xstartup
    Starting applications specified in /home/username/.vnc/xstartup
    Log file is /home/username/.vnc/your_hostname:1.log

Configuring The VNC Server

The commands that the VNC server should run when it starts up must be known. VNC needs to know just which graphical desktop it should connect to. We have to follow the below steps provided by our Support team to configure the VNS Server.

  1. Firstly end the VNC server instance that is running on port 5901 with the following command.
    vncserver -kill :1
  2. Then before modifying the xstartup file, back up the original with the command
    mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
  3. Now create a new xstartup file and open it in the text editor:
    nano ~/.vnc/xstartup
  4. We need VNC to start the desktop environment if it’s not already started. So include these commands in the file:
    #!/bin/bash
    xrdb $HOME/.Xresources
    startxfce4 &
  5. In order to confirm that the VNC server will be able to use this new startup file properly, we’ll need to make it executable.
    sudo chmod +x ~/.vnc/xstartup
  6. Finally, Now, restart the VNC server to make the configuration effective.
    vncserver

Connecting The VNC Desktop Securely

  1. Firstly, create an SSH connection on the local computer that securely forwards to the localhost connection for VNC. We can do this via the terminal with the following command:
    ssh -L 5901:127.0.0.1:5901 -C -N -l nonroot_username ip_address
  2. We can see the default Xfce desktop after the successful connection. Now select Use default config to configure the desktop.
  3. Finally, press CTRL+C in the terminal on the local machine to stop the SSH tunnel and return to the prompt. This also disconnects the VNC session.

Running VNC As A System Service

The following instructions set up the VNC server as a service.

  1. Firstly, create a new unit file called /etc/systemd/system/vncserver@.service with the help of any text editor.
    sudo nano /etc/systemd/system/vncserver@.service
  2. Include the following lines to the file. Remember to change the value of User, Group, WorkingDirectory, and the username in the value of PIDFILE according to the username.
    [Unit]
    Description=Start TightVNC server at startup
    After=syslog.target network.target
    
    [Service]
    Type=forking
    User=username
    Group=username
    WorkingDirectory=/home/username
    
    PIDFile=/home/username/.vnc/%H:%i.pid
    ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
    ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
    ExecStop=/usr/bin/vncserver -kill :%i
    
    [Install]
    WantedBy=multi-user.target

     

  3. The ExecStartPre command stops VNC if it’s already running. The ExecStart command starts VNC. Then sets the color depth to 24-bit color with a resolution of 1280×800. We can modify these startup options as well to meet the needs. Now save and then close the file.
  4. Now make the system aware of the new unit file with the below command:
    sudo systemctl daemon-reload
  5. Then enable the unit file.
    sudo systemctl enable vncserver@1.service
  6. Stop the current instance of the VNC server if it’s still running.
    vncserver -kill :1
  7. Then start it as you would start any other systemd service.
    sudo systemctl start vncserver@1
  8. We can verify that it started with this command:
    sudo systemctl status vncserver@1
  9. If it started correctly, the output should look like this:
    Output
    ● vncserver@1.service - Start TightVNC server at startup
       Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled)
       Active: active (running) since Thu 2019-10-10 17:56:17 UTC; 5s ago
      Process: 935 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=2)
      Process: 940 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1 (code=exited, status=0/SUCCESS)
     Main PID: 948 (Xtightvnc)
    . . .
    

     

  10. The VNC server will now be available when we reboot the machine. Start your SSH tunnel again with the command:
    ssh -L 5901:127.0.0.1:5901 -C -N -l username your_server_ip
  11. Lastly, make a new connection using the VNC client software to localhost:5901 to connect to the machine.

[Need help with another query? We are just a click away.]

Conclusion

To sum up, our Support team went over the DigitalOcean VNC Debian details including the installation and configuration process.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.