如何使用密码安装vncserver?

时间:2018-08-22 17:23:54

标签: centos vnc-server

我正在尝试使用Centos 6下的密码从bash脚本安装tigervnc-server。 我要这样做是因为我要自动执行VPS安装。有人知道怎么做这个吗?尝试在脚本中使用密码添加两行,因为它要求您输入两次密码,但没有成功,它说找不到命令,我也没有忘记。感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

#!/bin/bash

# Options:
PASSWORD="mysecret"
DISPLAY=":10"
VNCSERVER_OPTIONS="-geometry 1024x768 -alwaysshared"
PASSWD_PATH="$HOME/.vnc/passwd"
XSTARTUP_PATH="$HOME/.vnc/xstartup"
VNCSERVER="tightvncserver"
VNCPASSWD="tightvncpasswd"
# NOTE: you can change `tightvncpasswd` by `vncpasswd` if you don't use
#       TightVNC but it won't work in some VNC implementations
NEW_SESSION="exec gnome-session"

vncserver_stop() {
    # Kill server for this display if is running
    $VNCSERVER -clean -kill $DISPLAY
}

vncserver_start() {
    echo "$PASSWORD" | $VNCPASSWD -f > $PASSWD_PATH
    chmod 600 $PASSWD_PATH
    echo "$NEW_SESSION" > $XSTARTUP_PATH
    $VNCSERVER $DISPLAY $VNCSERVER_OPTIONS
}

case "$1" in
    start)
        vncserver_start
    ;;

    stop)
        vncserver_stop
    ;;

    restart)
       tightvnc_stop
       tightvnc_start
    ;;


    *)
        echo "Usage: $0 <start|stop|restart>"
        exit 1
esac