Debian11.6配置noVNC做远程桌面服务

1. 先安装 tigervnc。 要安装x11vnc,可看第10点

apt install tigervnc-standalone-server

2. 配置vnc的秘码。 

# 注意,配置的密码是登录时所用账号才能使用的,下面的vnc可登录账号就是 lgb
debian@lgb:~$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n

3. 使用给定的vnc账号开启vnc服务,关闭服务

# 注意,因为系统安装的是xfce4桌面,所以用了 /usr/bin/xfce4-session 
tigervncserver -xstartup /usr/bin/xfce4-session -geometry 1280x800 -localhost no :1

# 关闭服务的命令
tigervncserver -kill :1

 备注: /usr/bin/xfce4-session 这里根据你的桌面窗口管理程序来决定,例如我之前装了 x-window-system + i3 的组合,则变更为 /usr/bin/i3  ,有没有-session,需要进入文件夹具体看。

4.安装noVNC

apt install novnc python3-websockify

5. 按照第3步,打开vnc服务

6.配置noVNC

## 为noVNC服务生成一个私有证书
debian@lgb:~$ openssl req -x509 -nodes -newkey rsa:3072 -keyout novnc.pem -out novnc.pem -days 3650
Generating a RSA private key
..............++++
..++++
writing new private key to 'novnc.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN                            # 国家代码
State or Province Name (full name) [Some-State]:Guangdong       # 省
Locality Name (eg, city) []:Shenzhen                            # 市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:LGB  # 公司
Organizational Unit Name (eg, section) []:LGB-TEST              # 组织名称
Common Name (e.g. server FQDN or YOUR name) []:LGB-test         # 服务名称,随便起一个
Email Address []:[email protected]                                # 管理员邮箱

#将生成的证书 放到可用的路径中,这里是放到了/home内
debian@lgb:~$ mv novnc.pem /home/

# 启用noVNC
debian@lgb:~$ websockify -D --web=/usr/share/novnc/ --cert=/home/novnc.pem 41181 localhost:5901
WebSocket server settings:
  - Listen on :41181
  - Web server. Web root: /usr/share/novnc
  - SSL/TLS support
  - Backgrounding (daemon)

注意:也可以不用生成签名证书 ,直接启用noVNC,这时就是采用 http:// 的方式进行登录访问了!!

7. 通过网页登录noVNC。 截图中是我自己的测试

https://youserverip:41181/vnc.html    第6步省去证书生成: http://youserverip:41181/vnc.html 

8. 服务器重启后的操作

 因为tigervnc采用了指定账户登录的设置方式,所以如果服务器重新启动,则无法自动开启novnc,所以需要手动启动。

tigervncserver -xstartup /usr/bin/xfce4-session -geometry 1280x960 -localhost no :1
websockify -D --web=/usr/share/novnc/ --cert=/home/debian/novnc.pem 41181 localhost:5901

9. 额外的一点,关于root账户下打开edge浏览器的方法 

vim /usr/bin/microsoft-edge
# 在最末尾一行添加上 --user-data-dir --no-sandbox
exec -a "$0" "$HERE/msedge" "$@" --user-data-dir --no-sandbox

注意:每次更新edge,都需要重新修改该文件,它会被覆盖掉。

10.安装X11VNC并配置

apt install  x11vnc
reboot
# x11vnc的配置,要先配置密码,再构建用于systemd管理的 x11vnc.server
x11vnc -storepasswd /root/.vnc/passwd # 我这里是直接root用户设置的,存在的位置就是家目录中的.vnc/passwd
 
vim /etc/systemd/system/x11vnc.service
 
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
 
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /root/.vnc/passwd -rfbport 5900 -shared -o /var/log/x11vnc.log
## 上面的 -rfbport 5900 需要修改为和 虚拟机的 .xml 文件中的设置一致;若.xml为自动配置,则这里起到的作用就是指定端口号了!!
[Install]
WantedBy=multi-user.target
 
 
# 配置完成,保存后启动服务,并设置成开机自启动
systemctl start x11vnc
systemctl enable x11vnc

注意:由于x11vnc服务没有自动打开i3窗口管理器,所以需要安装登录管理器,比如 lightdm,用systemctl enable 来使其随机启动,然后采用上述方法配置x11VNC,则可省去上面第5步,打开VNC的过程。 

猜你喜欢

转载自blog.csdn.net/lggirls/article/details/129024338