Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Last active January 3, 2019 02:25
Show Gist options
  • Save nanpuyue/3917b7b7b1c14c70fc756c385cbf45bd to your computer and use it in GitHub Desktop.
Save nanpuyue/3917b7b7b1c14c70fc756c385cbf45bd to your computer and use it in GitHub Desktop.
#!/bin/bash
# author: nanpuyue <[email protected]>, https://blog.nanpuyue.com
# license: GPL 3.0, https://www.gnu.org/licenses/gpl-3.0.html
[ $(id -u) = 0 ] || {
echo "must run as root!" && exit 1
}
x11vnc -storepasswd || {
echo -e "please install x11vnc:\n\tsudo apt-get install x11vnc" && exit 1
}
cat > /etc/systemd/system/x11vnc.service << "EOF"
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -display :0 \
-auth /var/run/lightdm/root/:0 \
-o /var/log/x11vnc.log \
-rfbauth /root/.vnc/passwd \
-rfbport 5900 \
-forever -loop
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable x11vnc.service
systemctl start x11vnc.service
if [ -f /etc/init.d/iptables ];then
grep '\-A INPUT -p tcp -m tcp --dport 5900 -j ACCEPT' /var/lib/iptables/iptables-rules || {
iptables -I INPUT -p tcp -m tcp --dport 5900 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment