安装tightvnc

  • debian系

    1
    sudo apt-get install tightvncserver -y
  • redhat系

    1
    sudo yum install tightvncserver -y

设置vnc密码

  • 在当前用户的~/.ssh目录下
    1
    vncpasswd

开机自动启动

  • 设置开机启动,需要在/etc/init.d/中创建一个文件。例如tightvncserver:
    (注:启动脚本的名称,有和程序名一致的习惯)
1
sudo nano /etc/init.d/tightvncserver
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
#!/bin/sh
## # BEGIN INIT INFO
# Provides: tightvncserver
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop tightvncserver
## # END INIT INFO

## # Customize this entry
# Set the USER variable to the name of the user to start tightvncserver under
export USER='pi'
## # End customization required

eval cd ~$USER

case "$1" in
start)
# 启动命令行。此处自定义分辨率、控制台号码或其它参数。
su $USER -c '/usr/bin/tightvncserver -depth 16 -geometry 800x600 :1'
echo "Starting TightVNC server for $USER "
;;
stop)
# 终止命令行。此处控制台号码与启动一致。
su $USER -c '/usr/bin/tightvncserver -kill :1'
echo "Tightvncserver stopped"
;;
*)
echo "Usage: /etc/init.d/tightvncserver {start|stop}"
exit 1
;;
esac
exit 0
1
sudo chmod 755 /etc/init.d/tightvncserver
1
sudo update-rc.d tightvncserver defaults