If you're looking to manage your VPS remotely with a graphical user interface (GUI), installing a VNC (Virtual Network Computing) server is a great option. With VNC, you can access your VPS just like you're sitting in front of it, using your mouse and keyboard to interact with the desktop environment.
In this article, we’ll show you how to install a VNC server on both Ubuntu and CentOS, and how to connect to it remotely.
What Is a VNC Server?
VNC is a protocol that allows you to control a computer remotely by transmitting the graphical desktop to another device. It’s ideal for those who want to manage their server visually (as opposed to using a command-line interface) or need access to desktop-based applications on their VPS.
Why Use VNC?
- Graphical Interface: Makes it easier to interact with your VPS.
- Remote Access: Connect from anywhere to control your VPS.
- Convenience: Perfect for GUI-based tasks or configurations.
Prerequisites
- A VPS running Ubuntu or CentOS.
- Root or sudo access to your VPS.
- Basic familiarity with the command line.
Step 1: Install the Required Packages
For Ubuntu:
- Update your system:
sudo apt update && sudo apt upgrade -y
- Install the VNC server (we'll use TightVNC as an example):
sudo apt install tightvncserver -y
- Install a desktop environment (e.g., XFCE, a lightweight option):
sudo apt install xfce4 xfce4-goodies -y
For CentOS:
- Update your system:
sudo yum update -y
- Install the VNC server:
sudo yum install tigervnc-server -y
- Install a desktop environment (e.g., GNOME or XFCE):
sudo yum groupinstall "GNOME Desktop" -y
Step 2: Configure the VNC Server
For Ubuntu and CentOS:
- Set a password for your VNC session:
vncserver
You’ll be prompted to set a password (this will be required when you connect remotely).
- Stop the VNC server to configure it:
vncserver -kill :1
- Configure the VNC to use the correct desktop environment.
- For Ubuntu: Edit the
xstartup
file to start XFCE:
nano ~/.vnc/xstartup
Replace the file’s content with:
#!/bin/sh
xrdb $HOME/.Xresources
startxfce4 &
- For CentOS: You might need to use a different startup file or make adjustments based on the desktop environment you installed. For GNOME, you can leave it as is for now.
- Make the
xstartup
file executable:
chmod +x ~/.vnc/xstartup
Step 3: Start the VNC Server
Start the VNC server again:
vncserver :1
The :1
specifies the display number. If you want multiple sessions, you can use :2
, :3
, etc.
Step 4: Open the VNC Port in the Firewall
You’ll need to open the VNC port in your firewall (default is 5901 for display :1
).
For Ubuntu (using UFW):
sudo ufw allow 5901/tcp
For CentOS:
sudo firewall-cmd --zone=public --add-port=5901/tcp --permanent
sudo firewall-cmd --reload
Step 5: Connect to Your VPS Using a VNC Client
-
Install a VNC client on your local machine (e.g., TightVNC Viewer, RealVNC, or TigerVNC Viewer).
-
Connect to your VPS by entering the VPS IP address and the VNC port. For example:
<Your VPS IP>:5901
- Enter the password you set earlier to log in.
Step 6: (Optional) Secure the Connection with SSH
By default, VNC is not secure. To protect your data, it’s a good idea to tunnel the VNC connection over SSH:
- On your local machine, open a terminal and run:
ssh -L 5901:localhost:5901 your_username@your_vps_ip
- Now, connect to localhost:5901 in your VNC client instead of the direct IP.
Conclusion
You’ve successfully installed and configured a VNC server on your VPS running Ubuntu or CentOS, and learned how to connect to it remotely. This gives you a convenient graphical interface to manage your server, especially when handling tasks that are easier through a GUI.
For added security, always use SSH tunneling when connecting via VNC. If you need any help or have questions about setting up VNC on your VPS, feel free to reach out!