Skip to content

Instantly share code, notes, and snippets.

@adrianoluis
Forked from x43x61x69/vnc_install.sh
Last active August 17, 2026 03:28
Show Gist options
  • Select an option

  • Save adrianoluis/9bd34144f7401f58315e0988f8615f81 to your computer and use it in GitHub Desktop.

Select an option

Save adrianoluis/9bd34144f7401f58315e0988f8615f81 to your computer and use it in GitHub Desktop.
Steam Deck VNC Installation on Wayland
#!/bin/bash
#
# Script for installing krfb (KDE VNC server) on Steam Deck (Wayland).
#
# Replaces the old x11vnc script which no longer works because
# newer SteamOS versions use Wayland instead of X11.
#
# krfb is KDE's built-in desktop sharing tool and supports
# Wayland natively via xdg-desktop-portal.
#
# Install (interactive — prompts for password):
#
# sh -c "$(curl -fsSL <YOUR_GIST_RAW_URL>?$RANDOM)"
#
# Install (non-interactive — pass password directly):
#
# curl -fsSL <YOUR_GIST_RAW_URL>?$RANDOM -o vnc_install.sh
# sudo bash vnc_install.sh --password "YourPassHere"
#
# This will modify the root filesystem so it will probably get
# overwritten on system updates, but it is totally safe to
# re-run it. If something stops working after a SteamOS update,
# just launch it again.
#
# Based on the original x11vnc script by àngel "mussol" bosch
# Converted to Wayland/krfb
#
set -euo pipefail
# ── Colours for output ──────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No colour
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*"; }
# ── Parse arguments ────────────────────────────────────────────────
ARG_PASSWORD=""
while [[ $# -gt 0 ]]; do
case "$1" in
-p|--password)
if [ -n "${2:-}" ]; then
ARG_PASSWORD="$2"
shift 2
else
error "--password requires a value"
exit 1
fi
;;
-h|--help)
echo "Usage: sudo bash $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -p, --password PASS Set VNC password (min 6 chars)"
echo " -h, --help Show this help"
echo ""
echo "If --password is not provided, you will be prompted interactively."
exit 0
;;
*)
warn "Unknown option: $1 (ignoring)"
shift
;;
esac
done
# Validate password if provided via argument
if [ -n "${ARG_PASSWORD}" ] && [ ${#ARG_PASSWORD} -lt 6 ]; then
error "Password too short. Minimum 6 characters."
exit 1
fi
# ── Root check ──────────────────────────────────────────────────────
echo -n "Checking root permissions: "
if [ "$(id -ru)" -eq 0 ]; then
echo "OK"
else
echo "user is $(whoami), trying again as root"
exec sudo bash "$0" "$@"
exit 0
fi
# ── Detect the deck user ───────────────────────────────────────────
if [ -f /etc/sddm.conf.d/steamos.conf ]; then
DECK_USER=$(grep "^User=" /etc/sddm.conf.d/steamos.conf | cut -d"=" -f2)
else
DECK_USER="deck"
fi
DECK_HOME="/home/${DECK_USER}"
info "Detected user: ${DECK_USER}"
# ── Remove old x11vnc leftovers (if present) ───────────────────────
if command -v x11vnc &>/dev/null; then
warn "Old x11vnc installation detected — cleaning up"
killall x11vnc 2>/dev/null || true
rm -f "${DECK_HOME}/Desktop/VNC/Start VNC.desktop" 2>/dev/null || true
rm -f "${DECK_HOME}/Desktop/VNC/Stop VNC.desktop" 2>/dev/null || true
rm -f "${DECK_HOME}/Desktop/VNC/Set VNC Password.desktop" 2>/dev/null || true
rm -f "${DECK_HOME}/Desktop/VNC/Reinstall VNC.desktop" 2>/dev/null || true
rm -f "${DECK_HOME}/Desktop/VNC/vnc_startup.sh" 2>/dev/null || true
info "Old x11vnc shortcuts removed"
fi
# ── Disable readonly filesystem ────────────────────────────────────
info "Disabling readonly filesystem"
steamos-readonly disable
# ── Initialise pacman keys if needed ───────────────────────────────
if [ ! -e "/etc/pacman.d/gnupg/trustdb.gpg" ]; then
info "Initialising pacman keys"
pacman-key --init
pacman-key --populate archlinux
pacman-key --populate holo
fi
# ── Install krfb ───────────────────────────────────────────────────
info "Installing krfb (KDE VNC server for Wayland)"
pacman -Sy --noconfirm krfb
# ── Optionally remove x11vnc if installed ──────────────────────────
if pacman -Qi x11vnc &>/dev/null 2>&1; then
info "Removing old x11vnc package"
pacman -Rns --noconfirm x11vnc || true
fi
# ── Re-enable readonly filesystem ──────────────────────────────────
info "Re-enabling readonly filesystem"
steamos-readonly enable
# ── VNC password setup ─────────────────────────────────────────────
KRFB_CONFIG="${DECK_HOME}/.config/krfbrc"
CURRENT_PASS=""
SET_PASSWORD=false
VNC_PASS=""
# Check if a password already exists
if [ -f "${KRFB_CONFIG}" ]; then
CURRENT_PASS=$(grep "^unattendedPassword=" "${KRFB_CONFIG}" 2>/dev/null | cut -d'=' -f2-)
fi
if [ -n "${ARG_PASSWORD}" ]; then
# ── Password provided via --password flag (non-interactive) ──
VNC_PASS="${ARG_PASSWORD}"
SET_PASSWORD=true
info "Using password from --password argument"
else
# ── Interactive password prompt ─────────────────────────────
echo ""
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${CYAN} VNC Password Setup${NC}"
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
if [ -n "${CURRENT_PASS}" ]; then
echo " A VNC password is already set."
echo ""
read -r -p " Change it? [y/N]: " CHANGE_PASS
if [[ ! "${CHANGE_PASS}" =~ ^[Yy]$ ]]; then
info "Keeping existing password"
else
SET_PASSWORD=true
fi
else
SET_PASSWORD=true
fi
if [ "${SET_PASSWORD}" = true ]; then
while true; do
echo ""
read -r -s -p " Enter VNC password (min 6 chars): " VNC_PASS
echo ""
if [ ${#VNC_PASS} -lt 6 ]; then
error "Password too short. Minimum 6 characters."
continue
fi
read -r -s -p " Confirm password: " VNC_PASS_CONFIRM
echo ""
if [ "${VNC_PASS}" != "${VNC_PASS_CONFIRM}" ]; then
error "Passwords don't match. Try again."
continue
fi
break
done
fi
fi
# ── Write krfb configuration ──────────────────────────────────────
info "Configuring krfb"
mkdir -p "${DECK_HOME}/.config"
# Kill krfb if running (config changes require restart)
killall krfb 2>/dev/null || true
sleep 1
if [ "${SET_PASSWORD}" = true ]; then
# Write full config with the new password
cat > "${KRFB_CONFIG}" <<KRFBCFG
[General]
allowDesktopControl=true
[Security]
allowUnattendedAccess=true
noWallet=true
unattendedPassword=${VNC_PASS}
KRFBCFG
info "VNC password saved to config"
else
# Only create config if it doesn't exist
if [ ! -f "${KRFB_CONFIG}" ]; then
cat > "${KRFB_CONFIG}" <<'KRFBCFG'
[General]
allowDesktopControl=true
[Security]
allowUnattendedAccess=true
noWallet=true
KRFBCFG
else
# Ensure noWallet and unattended are enabled
if ! grep -q "noWallet=true" "${KRFB_CONFIG}" 2>/dev/null; then
if grep -q "\[Security\]" "${KRFB_CONFIG}"; then
sed -i '/\[Security\]/a noWallet=true' "${KRFB_CONFIG}"
else
printf '\n[Security]\nnoWallet=true\n' >> "${KRFB_CONFIG}"
fi
fi
if ! grep -q "allowUnattendedAccess=true" "${KRFB_CONFIG}" 2>/dev/null; then
if grep -q "\[Security\]" "${KRFB_CONFIG}"; then
sed -i '/\[Security\]/a allowUnattendedAccess=true' "${KRFB_CONFIG}"
else
printf '\n[Security]\nallowUnattendedAccess=true\n' >> "${KRFB_CONFIG}"
fi
fi
fi
fi
chown "${DECK_USER}:${DECK_USER}" "${KRFB_CONFIG}"
chmod 600 "${KRFB_CONFIG}"
# ── Create desktop shortcuts ──────────────────────────────────────
info "Creating desktop entries"
VNC_DIR="${DECK_HOME}/Desktop/VNC"
mkdir -p "${VNC_DIR}"
# --- Start VNC ---
cat > "${VNC_DIR}/Start VNC.desktop" <<'EOF'
[Desktop Entry]
Name=Start VNC (Wayland)
Comment=Start krfb VNC server for remote desktop access
Exec=krfb
Icon=krfb
Terminal=false
Type=Application
StartupNotify=false
Categories=Network;RemoteAccess;
EOF
# --- Stop VNC ---
cat > "${VNC_DIR}/Stop VNC.desktop" <<'EOF'
[Desktop Entry]
Name=Stop VNC
Comment=Stop the krfb VNC server
Exec=killall krfb
Icon=krfb
Terminal=false
Type=Application
StartupNotify=false
Categories=Network;RemoteAccess;
EOF
# --- Set VNC Password (helper script) ---
cat > "${VNC_DIR}/set_vnc_password.sh" <<'SETPW'
#!/bin/bash
# Helper script to change the VNC (krfb) unattended password
#
KRFB_CONFIG="$HOME/.config/krfbrc"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Set VNC Password"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Stop krfb if running
if pgrep -x krfb >/dev/null 2>&1; then
echo " Stopping krfb first..."
killall krfb 2>/dev/null || true
sleep 1
fi
while true; do
read -r -s -p " Enter new VNC password (min 6 chars): " VNC_PASS
echo ""
if [ ${#VNC_PASS} -lt 6 ]; then
echo " [ERROR] Password too short. Minimum 6 characters."
continue
fi
read -r -s -p " Confirm password: " VNC_PASS_CONFIRM
echo ""
if [ "${VNC_PASS}" != "${VNC_PASS_CONFIRM}" ]; then
echo " [ERROR] Passwords don't match. Try again."
continue
fi
break
done
# Update or set the password in krfbrc
if [ -f "${KRFB_CONFIG}" ]; then
if grep -q "^unattendedPassword=" "${KRFB_CONFIG}"; then
sed -i "s|^unattendedPassword=.*|unattendedPassword=${VNC_PASS}|" "${KRFB_CONFIG}"
else
# Add under [Security] section
if grep -q "\[Security\]" "${KRFB_CONFIG}"; then
sed -i "/\[Security\]/a unattendedPassword=${VNC_PASS}" "${KRFB_CONFIG}"
else
printf '\n[Security]\nunattendedPassword=%s\n' "${VNC_PASS}" >> "${KRFB_CONFIG}"
fi
fi
else
mkdir -p "$(dirname "${KRFB_CONFIG}")"
cat > "${KRFB_CONFIG}" <<PWCFG
[General]
allowDesktopControl=true
[Security]
allowUnattendedAccess=true
noWallet=true
unattendedPassword=${VNC_PASS}
PWCFG
fi
chmod 600 "${KRFB_CONFIG}"
echo ""
echo " [OK] Password updated!"
echo " Restart VNC (Start VNC shortcut) for changes to take effect."
echo ""
read -s -n 1 -p " Press any key to continue . . ."
echo ""
SETPW
chown "${DECK_USER}:${DECK_USER}" "${VNC_DIR}/set_vnc_password.sh"
chmod +x "${VNC_DIR}/set_vnc_password.sh"
cat > "${VNC_DIR}/Set VNC Password.desktop" <<EOF
[Desktop Entry]
Name=Set VNC Password
Comment=Change the VNC unattended access password
Exec=bash "${VNC_DIR}/set_vnc_password.sh"
Icon=krfb
Terminal=true
Type=Application
StartupNotify=false
Categories=Network;RemoteAccess;
EOF
# --- Reinstall VNC ---
cat > "${VNC_DIR}/Reinstall VNC.desktop" <<REINSTALL_EOF
[Desktop Entry]
Name=Reinstall VNC (Wayland)
Comment=Re-run the VNC install script after SteamOS updates
Exec=bash -c "sudo bash '${VNC_DIR}/vnc_install_wayland.sh'"
Icon=krfb
Terminal=true
Type=Application
StartupNotify=false
Categories=Network;RemoteAccess;
REINSTALL_EOF
# Fix ownership and permissions on all shortcuts
find "${VNC_DIR}" -name "*.desktop" -exec bash -c 'chown "'"${DECK_USER}:${DECK_USER}"'" "$1"; chmod +x "$1"' _ {} \;
# ── Create startup script ─────────────────────────────────────────
cat > "${VNC_DIR}/vnc_startup.sh" <<'STARTUP'
#!/bin/bash
#
# Startup script for krfb VNC on Steam Deck (Wayland)
#
# Note: On Wayland, the first time krfb runs in a session you may
# see a "Share your screen?" dialog from xdg-desktop-portal.
# You need to accept it once. After that, VNC clients can connect
# on port 5900.
#
# Check if krfb is already running
if pgrep -x krfb >/dev/null 2>&1; then
echo "krfb is already running."
exit 0
fi
# Start krfb
echo "Starting krfb VNC server..."
nohup krfb >/dev/null 2>&1 &
disown
echo "krfb started. Connect with a VNC client on port 5900."
STARTUP
chown "${DECK_USER}:${DECK_USER}" "${VNC_DIR}/vnc_startup.sh"
chmod +x "${VNC_DIR}/vnc_startup.sh"
# ── Copy this install script for easy re-runs ─────────────────────
SCRIPT_SRC="$(realpath "$0" 2>/dev/null || echo "")"
SCRIPT_DST="${VNC_DIR}/vnc_install_wayland.sh"
if [ -n "${SCRIPT_SRC}" ] && [ -f "${SCRIPT_SRC}" ] && [ "${SCRIPT_SRC}" != "${SCRIPT_DST}" ]; then
cp "${SCRIPT_SRC}" "${SCRIPT_DST}"
chown "${DECK_USER}:${DECK_USER}" "${SCRIPT_DST}"
chmod +x "${SCRIPT_DST}"
info "Install script saved to ${SCRIPT_DST} for easy re-runs"
fi
# ── Done ───────────────────────────────────────────────────────────
echo ""
info "============================================"
info " VNC (Wayland) installation complete!"
info "============================================"
echo ""
echo " What changed from the old x11vnc script:"
echo " • Uses krfb instead of x11vnc (Wayland-compatible)"
echo " • Connects on port 5900 (same as before)"
echo " • Uses xdg-desktop-portal for secure screen sharing"
echo ""
echo " Desktop/VNC folder shortcuts:"
echo " • Start VNC — launch the krfb VNC server"
echo " • Stop VNC — kill the krfb VNC server"
echo " • Set VNC Password — change your VNC password (terminal)"
echo " • Reinstall VNC — re-run this script after updates"
echo ""
echo " To auto-start VNC on login:"
echo " System Settings > Startup and Shutdown > Autostart"
echo " Click '+ Add...' > Login Script"
echo " Select: ${VNC_DIR}/vnc_startup.sh"
echo ""
read -s -n 1 -p "Press any key to continue . . ."
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment