1 |
curl -fsSL https://engineerisaac.com/download/mint_setup_x11vnc.sh | tr -d '\r' | sudo bash -c 'f="$(mktemp)"; cat >"$f"; chmod +x "$f"; bash "$f" </dev/tty; rm -f "$f"' |
Its for convince not requirement. However it will install VNC and prompt you to set a password.
The code executed is blow.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
#!/usr/bin/env bash
set -euo pipefail
# Linux Mint x11vnc setup:
# - Installs x11vnc if missing
# - Prompts to create/set a VNC password
# - Creates/updates a systemd service to start x11vnc at boot
#
# Optional env vars:
# VNC_BIND=lan|localhost (default: lan)
# OPEN_UFW=1|0 (default: 1) # only opens 5900 for RFC1918 ranges if ufw is active
#
# Run:
# sudo ./mint_setup_x11vnc.sh
if [[ "${EUID}" -ne 0 ]]; then
exec sudo -E bash "$0" "$@"
fi
VNC_BIND="${VNC_BIND:-lan}"
OPEN_UFW="${OPEN_UFW:-1}"
PASS_FILE="/etc/x11vnc.pass"
SERVICE_FILE="/etc/systemd/system/x11vnc.service"
LOG_FILE="/var/log/x11vnc.log"
ts() { date +"%Y%m%d_%H%M%S"; }
die() { echo "ERROR: $*" >&2; exit 1; }
backup_file() {
local f="$1"
[[ -f "$f" ]] || return 0
local b="${f}.bak.$(ts)"
cp -a "$f" "$b"
echo "Backup: $b"
}
ensure_pkg() {
if ! command -v x11vnc >/dev/null 2>&1; then
echo "Installing x11vnc..."
apt-get update -y
apt-get install -y x11vnc
else
echo "x11vnc already installed."
fi
}
ensure_password() {
local reset="n"
if [[ -f "$PASS_FILE" ]]; then
read -r -p "VNC password file exists at $PASS_FILE. Reset password? [y/N]: " reset || true
reset="${reset,,}"
else
reset="y"
fi
if [[ "$reset" == "y" || "$reset" == "yes" ]]; then
echo "Setting VNC password (you will be prompted)..."
x11vnc -storepasswd "$PASS_FILE"
chmod 600 "$PASS_FILE"
echo "Password saved to: $PASS_FILE"
else
chmod 600 "$PASS_FILE" || true
echo "Keeping existing password file."
fi
}
write_service() {
local x11vnc_bin
x11vnc_bin="$(command -v x11vnc || true)"
[[ -n "$x11vnc_bin" ]] || die "x11vnc binary not found after install."
local bind_flag=""
case "$VNC_BIND" in
lan) bind_flag="" ;;
localhost) bind_flag="-localhost" ;;
*) die "Invalid VNC_BIND='$VNC_BIND' (use 'lan' or 'localhost')" ;;
esac
local execstart
execstart="$x11vnc_bin -display :0 -auth guess -forever -shared -rfbauth $PASS_FILE -rfbport 5900 $bind_flag -o $LOG_FILE"
echo "Configuring systemd service: $SERVICE_FILE"
backup_file "$SERVICE_FILE"
mkdir -p "$(dirname "$SERVICE_FILE")"
{
echo "[Unit]"
echo "Description=x11vnc (X11 desktop VNC)"
echo "After=display-manager.service"
echo "Requires=display-manager.service"
echo
echo "[Service]"
echo "Type=simple"
echo "ExecStart=$execstart"
echo "Restart=on-failure"
echo "RestartSec=2"
echo
echo "[Install]"
echo "WantedBy=graphical.target"
} > "$SERVICE_FILE"
chmod 0644 "$SERVICE_FILE"
systemctl daemon-reload
systemctl enable --now x11vnc
}
maybe_open_ufw() {
[[ "$OPEN_UFW" == "1" ]] || { echo "OPEN_UFW=0, skipping firewall changes."; return 0; }
if command -v ufw >/dev/null 2>&1; then
if ufw status 2>/dev/null | grep -q "Status: active"; then
ufw allow from 192.168.0.0/16 to any port 5900 proto tcp >/dev/null || true
ufw allow from 10.0.0.0/8 to any port 5900 proto tcp >/dev/null || true
ufw allow from 172.16.0.0/12 to any port 5900 proto tcp >/dev/null || true
echo "UFW is active: allowed TCP/5900 from private LAN ranges (RFC1918)."
else
echo "UFW not active: no firewall changes made."
fi
else
echo "ufw not installed: no firewall changes made."
fi
}
main() {
ensure_pkg
ensure_password
write_service
maybe_open_ufw
echo
echo "Done."
echo "Service status:"
systemctl --no-pager --full status x11vnc || true
echo
echo "Notes:"
if [[ "$VNC_BIND" == "localhost" ]]; then
echo " - VNC is bound to localhost only. Use an SSH tunnel: ssh -L 5900:localhost:5900 user@HOST"
else
echo " - VNC is reachable on the LAN at port 5900 (if firewall/network allows)."
fi
}
main "$@" |
Comments