Created
September 17, 2024 10:00
-
-
Save teebow1e/3acf32a1b5f59bbf610684ae8d1cacb9 to your computer and use it in GitHub Desktop.
[Linux] Setup XFCE4+VNC for Ubuntu 22.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| export DEBIAN_FRONTEND="noninteractive" | |
| echo -e "[!] Installing XFCE4 and VNC server.." | |
| sudo apt update | |
| sudo apt install -y xfce4 xfce4-goodies tigervnc-standalone-server fonts-liberation | |
| sudo apt remove -y xfce4-screensaver | |
| echo -e "\n[!] Installing Chrome.." | |
| URL="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" | |
| DEB="/tmp/chrome.deb" | |
| wget ${URL} -O ${DEB} | |
| sudo dpkg -i ${DEB} || (set -e; sudo apt update; sudo apt install -f -y) | |
| rm ${DEB} | |
| echo -e "\n[!] Initializing VNC server now.." | |
| mypasswd="password" | |
| mkdir ~/.vnc | |
| echo $mypasswd | vncpasswd -f > ~/.vnc/passwd | |
| chown -R $USER:$USER /home/$USER/.vnc | |
| chmod 0600 /home/$USER/.vnc/passwd | |
| VNC_XSTARTUP_FILE=~/.vnc/xstartup | |
| echo -e "#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nstartxfce4" > $VNC_XSTARTUP_FILE | |
| chmod +x $VNC_XSTARTUP_FILE | |
| SERVICE_FILE=/etc/systemd/system/[email protected] | |
| echo -e "\n[!] Creating VNC service file at $SERVICE_FILE" | |
| sudo bash -c "cat > $SERVICE_FILE" <<EOL | |
| [Unit] | |
| Description=Start TigerVNC server at startup | |
| After=syslog.target network.target | |
| [Service] | |
| Type=simple | |
| User=$USER | |
| Group=$USER | |
| WorkingDirectory=/home/$USER | |
| PIDFile=/home/$USER/.vnc/%H:590%i.pid | |
| ExecStartPre=-/bin/sh -c "/usr/bin/vncserver -kill :%i > /dev/null 2>&1" | |
| ExecStart=/usr/bin/vncserver -fg -depth 24 -geometry 1920x1080 -localhost no :%i | |
| ExecStop=/usr/bin/vncserver -kill :%i | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOL | |
| echo -e "\n[!] Finishing..." | |
| sudo chmod +x /etc/systemd/system/[email protected] | |
| sudo systemctl daemon-reload | |
| sudo systemctl enable [email protected] | |
| vncserver -kill :* | |
| sudo systemctl start vncserver@1 | |
| echo -e "\n[!] Done! Please check the service status and whether the VNC port is opened." | |
| sudo systemctl status vncserver@1 | |
| netstat -ntlp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment