Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Last active April 20, 2023 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilangvperdana/8fd328d2c56978ac028067c12bbf34d5 to your computer and use it in GitHub Desktop.
Save gilangvperdana/8fd328d2c56978ac028067c12bbf34d5 to your computer and use it in GitHub Desktop.
Remote Ubuntu Desktop with TightVNC

TightVNC

Make your ubuntu server to GUI Based

Installation

sudo apt install xfce4 xfce4-goodies -y 
sudo apt install tightvncserver -y 
vncserver

Initiate Password TightVNC

vncpasswd

Deactivate session

Dapat dilihat pada /root/.vnc/

vncserver -kill :1

Create startup service

mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
nano ~/.vnc/xstartup
#!/bin/bash
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
chmod +x ~/.vnc/xstartup

Start

vncserver -localhost

Run on spesific port

vncserver -rfbport 6901
IP:6901

Check Port

sudo netstat -tulpn | grep 690

Port Forward from 6901

ssh -L 6901:localhost:6901 -C -N -l user 192.168.x.x
Access on localhost:6901

Make it Systemd

  • Root Version
sudo nano /etc/systemd/system/vncserver@.service
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=root
Group=root
WorkingDirectory=/root/

PIDFile=/root/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -rfbport 6901 -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
sudo systemctl start vncserver@1
sudo systemctl status vncserver@1
  • Another User Version
sudo nano /etc/systemd/system/vncserver@.service
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User=anotheruser
Group=anotheruser
WorkingDirectory=/home/anotheruser/

PIDFile=/home/anotheruser/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -rfbport 6901 -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
sudo systemctl start vncserver@1
sudo systemctl status vncserver@1

GNOME Desktop Ubuntu Server

sudo apt update

sudo apt install x11vnc xvfb gnome-shell ubuntu-gnome-desktop autocutsel gnome-core gnome-panel gnome-themes-standard gnome-settings-daemon metacity nautilus gnome-terminal dconf-editor gnome-tweaks yaru-theme-unity yaru-theme-gnome-shell yaru-theme-gtk yaru-theme-icon fonts-ubuntu tmux fonts-emojione

x11vnc -storepasswd
reboot

export DISPLAY=:0
Xvfb $DISPLAY -screen 0 2048x1200x16 &
sudo -u ubuntu gnome-session &
x11vnc -usepw -forever -repeat -shared -display :0

# Option: Endlessly repeat x11vnc invocation in case it fails at some point.
while :; do x11vnc -usepw -forever -repeat -shared -display :0 ; done

Remote from Browser with Apache Guacamole

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment