3

Ubuntu 20.04 Desktop VNC远程控制的两种方法

 1 year ago
source link: https://mianao.info/2022/06/09/363504
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

安装了 Ubuntu 20.04 desktop 后,因为本身已有 Gnome ,所以要远程控制时和一般的无桌面服务器版本的需求不一样,经过我搜索测试有以下两种方法可实现:

系统自带远程控制

1.设置-共享-屏幕共享

打开屏幕共享开关,设置访问密码,可以自动连接,这样就不用本机点击确认了:

share.png

2.dconf 更改系统配置

打开一个终端,输入下面的命令,安装 dconf-editor 系统配置编辑器:

sudo apt-get install dconf-editor

安装完毕后在应用程序中可以找到新增的 dconf 应用;
启动这个应用时会有这样的警告,所以一定小心使用,不要修改本文提到的选项之外的任何选项!
按照路径 /org/gnome/desktop/remote-access 找到 requlre-encryption,把原先默认的开启状态改为关闭

dconf.png

3.下载 VNC Viewer 客户端连接

Windows 下可以选择无须安装的绿色版 standalone EXE:
客户端下载:https://www.realvnc.com/en/connect/download/viewer/

VNCdownload.png

运行客户端,输入 IP 和端口号 5900

VNC.png

VNC Server 远程控制

Ubuntu 20.04 desktop 默认已自带桌面 Gnome,但我配置多次发现连接后远程屏幕显示灰色,鼠标是个黑 x,原因暂时未找到。
于是我选择另外一个方案:

1.安装 gnome-session-flashback

sudo apt-get install gnome-session-flashback

根据提示,有可能还需要安装 gdm3,如没有就不用管。

2.安装 VNC Server

sudo apt-get install tigervnc-standalone-server  #要安装 tigervnc-standalone 版本,普通版本无法输入其他指令,如 -list

若有其他提示则安装:sudo apt-get install tigervnc-xorg-extension

安装完毕后,运行 vncserver 命令(不要在 root 下执行):

You will require a password to access your desktops.

Password:
Verify:
Would you like to enter a view-only password (y/n)? n
/usr/bin/xauth:  file /home/typhoon/.Xauthority does not exist

New 'server2.typhoon.org:1 (typhoon)' desktop at :1 on machine server2.typhoon.org

Starting applications specified in /etc/X11/Xvnc-session
Log file is /home/typhoon/.vnc/server2.typhoon.org:1.log

Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/typhoon/.vnc/passwd :1 to connect to the VNC server.

系统将提示您输入并确认密码,该密码和系统密码没有关系。以及是否将其设置为仅查看密码,记得选 N

3.配置 xstartup 文件:

编辑 xstartup:

vi ~/.vnc/xstartup

修改 xstartup 文件里的内容,测试使用正常的配置如下:

#!/bin/sh                                                                       

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:GNOME"
export XDG_MENU_PREFIX="gnome-flashback-"
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey    #设置背景色
vncconfig -iconic &
gnome-terminal &    #连接后会直接打开一个terminal窗口
nautilus &    #连接后会直接打开一个文件窗口
gnome-session --session=gnome-flashback-metacity --disable-acceleration-check &

修改完毕后更改权限:

sudo chmod +x  ~/.vnc/xstartup

4.启动和关闭 VNC Server:

vncserver -localhost no  #启动 VNC,单独 vncserver 命令会导致远程无法连接
vncserver -kill :1  #关闭 5901 端口 VNC 服务
vncserver -list  #查看连接端口
vncpasswd  #重设密码

5.VNC Viewer 客户端远程控制

下载客户端如上文链接。
运行客户端后,输入 IP 和端口号 5901(根据 vncserver -list 查看连接端口,:1=5901),按提示输入密码。

附 Linux 系统相关命令:

sudo useradd -r -m -s /bin/bash username  #新建一个用户
su - username  #切换用户
sudo passwd  #设置密码
sudo ufw disable   #关闭防火墙,如有异常可关闭防火墙,20.04 我没关闭也可正常连接
sudo ufw status  #查看防火墙状态

推荐目前我已使用 5 年觉得还算稳定可靠的便宜 VPS

Vultr:欢迎使用推荐链接,新用户充值有奖励 100 美元,谢谢! https://www.vultr.com/?ref=9125823-8H
虽然可能会有 IP 被墙,但欧美亚的机房可以随便切换,美国机房最低每月 $3.5:512M 内存 500G 流量。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK