ubuntu 20.04 vncserver 开机自启动 通过 sudo nano /etc/init.d/vncserver
时间: 2023-06-28 13:09:50 浏览: 394
将以下内容复制并粘贴到该文件中,然后保存并退出:
```
#!/bin/sh -e
# /etc/init.d/vncserver
### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: networking
# Default-Start: 3 4 5
# Default-Stop: 0 6
### END INIT INFO
PATH="$PATH:/usr/X11R6/bin/"
# The Username:Group that will run VNC
export USER="yourusername"
#${RUNAS}
export HOME="/home/${USER}"
# The display that VNC will use
DISPLAY="1"
# Color depth (between 8 and 32)
DEPTH="16"
# The Desktop geometry to use.
#GEOMETRY="<width>x<height>"
#GEOMETRY="800x600"
#GEOMETRY="1024x768"
GEOMETRY="1280x1024"
#GEOMETRY="1440x900"
#GEOMETRY="1920x1080"
# The name that the VNC Desktop will have.
NAME="my-vnc-server"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions
case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;
stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;
restart)
$0 stop
$0 start
;;
esac
exit 0
```
然后,将该文件标记为可执行文件:
```
sudo chmod +x /etc/init.d/vncserver
```
接下来,使用以下命令将该文件添加到启动脚本中:
```
sudo update-rc.d vncserver defaults
```
最后,重新启动系统以测试自启动是否成功:
```
sudo reboot
```
希望这个回答能帮到你!
阅读全文