记录日常点点滴滴,欢迎来到我的小站。

0%

Ubuntu 18.10 安装X11VNC 远程访问 包含14.04~

启动Ubuntu的软件中心,选择“X11VNC服务器”,进行安装。当然也可以用sudo apt-get install x11vnc命令安装。

接下来创建登陆密码

1
sudo x11vnc -storepasswd

输入和确认之后,密码被保存到了用户的密码目录下

再设置X11VNC的密码文件:

1
sudo x11vnc -storepasswd in /etc/x11vnc.pass

将密码文件复制过去:

1
sudo cp /root/.vnc/passwd /etc/x11vnc.pass

此处注意,分为两个版本

1
2
3
4
5
6
7
8
9
Ubuntu14.04以前
打开/etc/init/x11vnc.conf文件,粘贴以下内容。如果没有这个文件,就用文本工具创建一个。端口:5900,自己可以定义。
start on login-session-start
script
/usr/bin/x11vnc -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes
-noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o
/var/log/x11vnc.log
end script

Ubuntu15.04以后
Ubuntu15.04以后得服务管理器已经切换到了systemd中,其系统服务脚本目录为:/lib/systemd/system/
所以要自动启动x11vnc,需要在系统服务目录中新建服务文件

1
sudo vi /lib/systemd/system/x11vnc.service

拷贝下面的内容到文件中:

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/USERNAME/.vnc/passwd -rfbport 5900 -shared
guess用户被禁时,使用root
ExecStart=/usr/bin/x11vnc -auth root -forever -loop -noxdamage -repeat -rfbauth /home/USERNAME/.vnc/passwd -rfbport 5900 -shared

[Install]
WantedBy=multi-user.target

然后以774的权限保存在根目录:

1
sudo chmod 774 /lib/systemd/system/x11vnc.service

然后再设置二开机自启服务:

1
sudo systemctl enable x11vnc.service

下面给出几个常用的设置命令
systemctl start nginx.service 启动服务
systemctl enable nginx.service设置开机自启动
systemctl disable nginx.service停止开机自启动
systemctl disable nginx.service查看服务当前状态
systemctl status nginx.service查看服务当前状态
systemctl restart nginx.service重新启动服务
systemctl list-units –type=service查看所有已启动的服务

现在遇到一个问题,由于升级了17.10版后,x11vnc无法在登录页面启动了。需要账户自启动。
我们在这里已root为例添加 18.10版的root自启动

首先确保你的Ubuntu已经开启root登录
未开启的请参考
https://www.ttwinbug.com/thread-9981-1-1.html

要保证Root自启动还要修改以下文件

1
2
3
4
5
6
7
/etc/gdm3/custom.conf
[daemon]
AutomaticLoginEnable=true
AutomaticLogin=root
...
[security]
AllowRoot=true

这样重新启动即可实现自启动并开启x11vnc服务。

x11vnc -forever -shared -rfbauth ~/.vnc/passwd
-forever keep listening for more connections //永远保持连线listing
-shared more than one viewer can connect at the same time //允许多个连接
-rfbauth use authentication on RFB protocol //需要认证