1. Install tiger vnc server
Install the TigerVNC server package using the apt command below.
sudo apt update sudo apt install tigervnc-standalone-server
Enter Y to confirm and press Enter to continue the installation. Now the installation will start.
2. Initialize the VNC server
Switch to the user you need to use
cd username
Initialize the VNC server configuration using the following command. The command-line vncserver can be used to manage VNC server configuration, including initialization, checking status, setting startup scripts, and more.
vncserver
After entering the password, select n to not set a read-only user
If you need to change the password
vncpasswd
3. Configure vnc service
vncserver -kill :1
install gnome-components
sudo apt install gnome-session gnome-terminal ubuntu-desktop
Create a new ~/.vnc/xstartup file to run the desktop environment on boot
nano ~/.vnc/xstartup
#!/bin/sh # Start up the standard system desktop unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS /usr/bin/gnome-session [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources x-window-manager &
Add permissions
chmod +x ~/.vnc/xstartup
start again
vncserver -localhost no :1
View started processes
vncserver -list
end process
vncserver -kill :1
4. Add user
sudo vim /etc/tigervnc/vncserver.users
join in
:1=username
5. Configure vnc as a service
create a new file
sudo nano /etc/systemd/system/[email protected]
Ubuntu 22.04 fill in the following fields (note that change wind to your username, 32 is the highest color depth to 32, and 1920x1080 is the resolution)
[Unit] Description=Start TigerVNC server at startup After=syslog.target network.target [Service] Type=forking User=wind Group=wind WorkingDirectory=/home/wind PIDFile=/home/wind/.vnc/%H:590%i.pid ExecStartPre=-/bin/sh -c "/usr/bin/vncserver -kill :%i > /dev/null 2>&1" ExecStart=/usr/bin/vncserver -depth 32 -geometry 1920x1080 -localhost :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
Ubuntu 20.04 fill in the following fields
[Unit] Description=Start TigerVNC server at startup After=syslog.target network.target [Service] Type=forking User=YOUR_USERNAME Group=YOUR_USERNAME WorkingDirectory=/home/YOUR_USERNAME PIDFile=/home/YOUR_USERNAME/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
Press Ctrl+O and press Enter to save, Ctrl+x to exit
Set up autostart
sudo systemctl daemon-reload sudo systemctl enable [email protected]
end previous process
vncserver -kill :1
open as a service
sudo systemctl start vncserver@1
check status
sudo systemctl status vncserver@1
5. Set up ssh encryption
ssh -L 59000:localhost:5901 -C -N -l server_user_name server_ip_address
reference: