用BASH以编程方式设置TightVNC

时间:2015-06-02 21:10:05

标签: bash debian expect vnc-server tightvnc

我正在编写一个脚本来在许多基于debian的设备上设置VNC(以及其他内容)。我想在这个设置中包含VNC(特别是如果可能的话,包括tightVNC)并让它设置一个给定的密码(由脚本随机生成)。问题是,我发现的每一个指南似乎都假设一个人正在做这个,并准备好坐下来输入密码然后按回车键。我似乎无法让Bash向VNC回复密码(它总是说密码太短')我也不能期望'工作正常。

我发现的示例指南如下所示: http://www.penguintutor.com/linux/tightvnc

我正在寻找类似的东西:

#!/bin/bash
echo "Going to configure VNC"
#turn on vnc server
tightvncserver
#spit out password to vnc server for first run only
echo $password
#confirm the pw
echo $password

但是,在每个virginal运行的tightvncserver上,它总是要求手动输入密码:

Going to configure VNC

You will require a password to access your desktops.

Password: Password too short

我怎样才能#1绕过这个,或者#2使用bash / expect给它一个密码让它快乐?

1 个答案:

答案 0 :(得分:5)

# Configure VNC password
umask 0077                                        # use safe default permissions
mkdir -p "$HOME/.vnc"                             # create config directory
chmod go-rwx "$HOME/.vnc"                         # enforce safe permissions
vncpasswd -f <<<"$password" >"$HOME/.vnc/passwd"  # generate and write a password

如果您对tightvnc的包装使用~/.vnc/以外的其他位置作为passwd文件,则修改为品尝。

如果您有单独的仅查看和完全控制密码,则:

vncpasswd -f <<<"$full_password"$'\n'"$view_password" >"$HOME/.vnc/passwd"

如果您需要与/bin/sh兼容(或者不使用#!/bin/bash shebangs),则会改为:

vncpasswd -f >"$HOME/.vnc/passwd" <<EOF
$full_password
$view_password
EOF
相关问题