从 ssh 客户端启动 vino vnc 服务器

从 ssh 客户端启动 vino vnc 服务器

首先:我整天都在谷歌搜索,并在不同的论坛上尝试了几种建议,但都没有成功

问题:我无法通过 ssh 在远程计算机上启动 vnc 服务器附加信息:

  • 主机:Ubuntu 12.04
  • 客户端:VritualBox 中的 Ubuntu 14.04
  • 我没有远程机器的物理访问权限

这有效:

ssh -Y user@hostname

当我检查显示屏时,我得到了这个:

$ echo $DISPLAY
localhost:10.0

现在我启动 vnc 服务器:/usr/lib/vino/vino-server

=> 这有效,但是当我连接到 vnc 时,我看到我自己的屏幕(来自 ssh 客户端)而不是远程屏幕

它似乎localhost:10.0占用了我的本地屏幕。我说得对吗?

我也尝试了这个,因为我想要远程屏幕:

/usr/lib/vino/vino-server --display :0.0

其结果如下:

$ /usr/lib/vino/vino-server --display 0.0

(process:6843): Gtk-WARNING **: Locale not supported by C library.
    Using the fallback 'C' locale.
Cannot open display: 0.0
Run 'vino-server --help' to see a full list of available command line options

为什么无法打开显示0.0?

答案1

在另一个论坛 forum.developer.nvidia.com 上,“nekokeitai”写了一些对我有用的东西。这些命令可以通过 ssh 在远程 Ubuntu 18.04 PC 上使用:

安装 vino:

sudo apt install vino

找到连接的 UUID,并将它们作为逗号分隔列表放在最后一行配置的方括号内。不过,我只尝试在单引号内使用一个 UUID:

nmcli connection show

配置vino:

gsettings set org.gnome.Vino prompt-enabled false
gsettings set org.gnome.Vino require-encryption false
dconf write /org/gnome/settings-daemon/plugins/sharing/vino-server/enabled-connections "['']"

开始 vino:

export DISPLAY=:0 && /usr/lib/vino/vino-server

现在,在本地 PC 上使用带有 VNC 协议的 remmina 连接到远程 PC。

答案2

下面是我用来将 vino 安装到遥控器上的一些脚本。

在主安装脚本中,我将仅包含调用 vnc_access 脚本的代码(该脚本位于子目录“vnc”中,但将其更改为放置第二个脚本的任何位置。

if [ ! -z "$install_vnc" ] ; then
    user_password='password'
    vnc_password='password'
    vnc_script="${BASH_SOURCE%/*}/vnc/vnc_access.sh"

    printf '\n\tSetting up vino-server on host...\n' >&2

    ssh $host_user_name@$host_address \
        "bash -s" < "$vnc_script" $user_password "'$vnc_password'"

    printf '\n\tDone sending vnc to host.\n' >&2
fi

这是 vnc_access.sh 脚本

#!/bin/bash
#
# Tools to enable and configure vino for vnc access

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# parse arguments
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
user_password=$1
vino_password=$2

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# initialize values
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vino_password_binary="$(echo -n ${vino_password} | base64)"

declare -A settings
settings[alternative-port]="uint16 5900"
settings[authentication-methods]="['vnc']"
settings[disable-background]=false
settings[disable-xdamage]=false
settings[enabled]=true
# enum 'never' 'always' 'client'
settings[icon-visibility]="'client'"
settings[lock-screen-on-disconnect]=false
settings[mailto]="''"
settings[network-interface]="''"
settings[notify-on-connect]=true
settings[prompt-enabled]=false
settings[require-encryption]=false
settings[use-alternative-port]=false
settings[use-upnp]=false
settings[view-only]=false
settings[vnc-password]="'$vino_password_binary'"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# main
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# We need to have sudo enabled to do many of these tasks, 
#  this is a bit of a hack, but it gets the job done.
printf "Enabling sudo privileges...\n" >&2
echo $user_password | sudo -S whoami >/dev/null
printf "\n" >&2

# If vino is not installed, install it
if [ -z "$(dpkg -l | egrep -i 'vino')" ] ; then
    printf "Installing vino...\n" >&2
    sudo apt-get update
    sudo apt-get install -y vino
fi

# Make sure we are performing these operations of the remotes display.
printf "Forwarding X org Display...\n" >&2
export DISPLAY=:0
sudo xhost +

# Loop through settings and configure vino.
for setting in "${!settings[@]}" ; do
    current_value="$(gsettings get org.gnome.Vino "$setting")"
    to_value="${settings[$setting]}"
    if [[ "$current_value" != "$to_value" ]] ; then
        printf "changing Vino's ${setting} from ${current_value} to ${settings[$setting]}\n" >&2
        DISPLAY=:0 sudo gsettings set org.gnome.Vino "$setting" ${settings[$setting]}
    fi
done

# Vino requires a reboot to work. If someone can find out how to do this with
#  out rebooting or logging out, let me know.
sudo reboot

相关内容