Last active
January 3, 2019 02:25
-
-
Save nanpuyue/3917b7b7b1c14c70fc756c385cbf45bd to your computer and use it in GitHub Desktop.
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 | |
# 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