适用于VPS,以下命令均在root用户下进行

安装所需程序

apt-get update && apt-get upgrade
apt-get -y install tightvncserver xfce4 xfce4-goodies

设置VNC密码

vncpasswd

编辑/etc/init.d/vncserver

#!/bin/bash
PATH="$PATH:/usr/bin/"
export USER="root"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
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

编辑~/.vnc/xstartup

#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
startxfce4 &

修改文件权限并启动VNC服务

chmod +x ~/.vnc/xstartup && chmod +x /etc/init.d/vncserver && service vncserver start && update-rc.d vncserver defaults

可以连接5901端口了~