如何通过SSH设置远程桌面共享?

有没有办法通过SSH查看(和控制)远程桌面? 我无法物理访问远程主机。

方法1:

这可以通过vino vnc server&remmina实现(两者都默认使用ubuntu;如果没有通过运行sudo apt-get install remmina )。 然后在终端提示符中从本地计算机运行以下命令:

  1. ssh -Y gman@remote 。 使用可信的X11转发,否则它不会工作

  2. vino-preferences 。 它将打开vino-preferences。

    维诺偏好

  3. 同时单击“ configure network automatically to accept connection但是不要输入任何密码,它的base64编码 。 然后单击关闭。 然后运行:

     sudo -s export DISPLAY=:0.0 xhost + /usr/lib/vino/vino-server & 

    它将启动vino服务器。

  4. 从服务器注销:

     xhost - Press CTRL+C twice exit exit 
  5. 然后打开remmina 。 在协议下选择vnc

    server字段的basic选项卡下放置服务器地址

    在ssh选项卡上单击enable ssh tunnel 。 在ssh authentication ,它可以是passwordpublic key

    remmina偏好

    点击保存。 然后双击connection-name(如图所示的home-desktop)开始浏览远程桌面。


方法2:

x11vnc是一个简单的VNC服务器,你不必乱用Gnome设置或500防​​火墙,只需在你的所有计算机上安装x11vnc (使用puppet或你用于质量控制的任何东西)。

然后从您的本地计算机运行:

 ssh user@host -L 5900:localhost:5900 "x11vnc -display :0 -noxdamage" 

显然交换user@host以获取远程计算机的用户名和主机名/ IP。

然后使用您选择的VNC客户端连接到localhost:5900 。 SSH命令在远程计算机上启动vnc服务器,然后通过SSH隧道回传该端口。 您不必打开任何端口(只要您已经可以SSH)。

如果您的计算机具有有趣的显示设置,您可能最好在SSH命令中取消-display :0段。 x11vnc然后将自动尝试找到正确的显示。


来源: askubuntu

解决方案概述

假设您已在主机上设置了OpenSSH Server ,则必须首先在主机上启用桌面控制。 如果您可以先在本地启用主机上的桌面控制,请前往1a。 如果必须首先在主机上远程启用桌面控制,请前往1b。

接下来,在客户端计算机上创建远程桌面客户端配置文件,以便通过SSH隧道连接到主机,最终通过SSH隧道查看和控制主机的桌面。

1A。 本地启用主机远程控制

在主机上执行以下操作:

 vino-preferences 
  • vino-preferences也在Desktop Sharing下的Dash中

在此处输入图像描述

  1. 勾选Allow other users to view your desktop
  2. 勾选Allow other users to control your desktop
  3. 勾选Require the user to enter this password
  4. 输入难以猜测的密码

1B。 远程启用主机远程控制

在客户端计算机上执行以下操作,将123.123.12.3替换为主机的IP地址:

 ssh -Y 123.123.12.3 
  • -Y,启用可信的X11转发。 受信任的X11转发不受X11 SECURITY扩展控制的约束。
 vino-preferences 
  • vino-preferences也在Desktop Sharing下的Dash中

在此处输入图像描述

  1. 勾选Allow other users to view your desktop
  2. 勾选Allow other users to control your desktop
  3. 勾选Require the user to enter this password
  4. 输入难以猜测的密码

在客户端计算机上创建远程桌面客户端配置文

在客户端计算机上执行以下操作:

 remmina 
  • Remmina也在Remmina Remote Desktop Client下的Dash中

Ctrl + N或连接>新建

在此处输入图像描述

  1. 填写您的IP地址[123.123.12.3],其中显示Server
  2. 切换到SSH选项卡

在此处输入图像描述

  1. 勾选Enable SSH Tunnel
  2. 将Desktop Client指向非标准SSH端口
  3. 设置SSH Authentication 和模式

查看和控制主机

在客户端计算机上,当询问的密码时,输入它以创建SSH隧道。 当询问VNC密码时,请输入先前输入主机的密码。

如果在此步骤成功,您现在应该通过SSH隧道从客户端计算机查看和控制主机的桌面。

  1. 您可以使用ssh启动vnc会话
  2. 使用Xnest和X11转发远程启动会话并将其转发到当前计算机。 (我不时用我的pi执行此操作) 手册页

我像这样使用Xnest

  • Xnest :1 -ac &
  • 然后DISPLAY=:1 . /etc/X11/Xsession DISPLAY=:1 . /etc/X11/Xsession

我能够使用以下脚本从远程ssh连接设置新的Ubuntu 16.04安装:

 #!/斌/庆典
 export DISPLAY =:0
 read -e -p“VNC Password:” -  i“ubuntu”密码
 dconf write / org / gnome / desktop / remote-access / enabled true
 dconf write / org / gnome / desktop / remote-access / prompt-enabled false
 dconf write / org / gnome / desktop / remote-access / authentication-methods“['vnc']”
 dconf write / org / gnome / desktop / remote-access / require-encryption false
 dconf写/ org / gnome / desktop / remote-access / vnc-password \“\'$(echo -n $ password | base64)\'\”
 dconf dump / org / gnome / desktop / remote-access /
 sudo service lightdm restart

引用对于任何字符串设置(引号内的单个刻度)都很重要。 要使dconf能够写入,它需要访问XWindows,这就是为什么需要导出DISPLAY部分。 我认为你仍然需要登录到实际的Ubuntu机器上的桌面以便在此之后与VNC连接。 dump命令只是用于确认所有设置保持不变,你真的不需要它。

如果您希望始终保持显示,可以选择执行此操作:

 dconf write / org / gnome / desktop / screensaver / lock-enabled false
 dconf写/ org / gnome / desktop / screensaver / ubuntu-lock-on-suspend false
 dconf write / org / gnome / desktop / session / idle-delay“uint32 0”

如何在不转发X的情况下远程启动Vino服务器(仅限命令行)

以将共享其桌面并将端口5900转发到localhost上的同一端口的用户身份登录远程计算机。 使用PuTTY,重定向在Connection / SSH / Tunnels中设置。 使用命令行,使用:

  ssh -L 5900:localhost:5900 user@remote-computer 

安装vino-server如果尚未安装)。 例如:

 sudo apt install vino 

启用桌面共享(匹配第1行和第2行的显示编号):

 echo $DISPLAY export DISPLAY=:0 dbus-launch --exit-with-session gsettings set org.gnome.Vino enabled true dbus-launch --exit-with-session gsettings set org.gnome.Vino prompt-enabled false dbus-launch --exit-with-session gsettings set org.gnome.Vino require-encryption false /usr/lib/vino/vino-server 

启动VNC查看器并连接到localhost以获取VNC服务器地址。

基于@Khurshid Alam回答我提出以下片段:

ssh $TARGETHOST -L 5900:localhost:5900 "x11vnc -localhost -display :0 -noxdamage" &; sleep 10 && vinagre localhost

  • 这是一个不需要任何交互的命令

  • 它创建带端口转发的SSH隧道,以合理安全的方式启动x11vnc并启动并连接VNC查看器

  • 它需要目标主机上的x11vnc,但不需要进一步配置

  • 它需要在您的PC上使用vinagre,但您可以轻松地将其更改为另一个VNC查看器