服务器图形化显示:x11vnc配置简明教程暨踩坑记

服务器 0

配置x11:一个远程的图形化传输协议

在服务器上:

sudo vim /etc/ssh/sshd_config

修改配置:

AllowAgentForwarding yesAllowTcpForwarding yesX11Forwarding yesX11DisplayOffset 10X11UseLocalhost no

重启sshd service

sudo service sshd restart

 在本地:

设置~/.ssh/config

Host <host_name>  HostName <ip>  User <user_name>  ForwardX11 yes  ForwardX11Trusted yes  ForwardAgent yes

测试:

可以尝试ssh <host_name>看能否连接到远程

配置x11vnc:一个传输的客服端

- 如果已经有桌面、但需要远程访问桌面:

在服务器上:

1. 安装x11vnc以及必要dependency

sudo apt-get install x11vnc net-tools

2. 运行x11vnc 

x11vnc -display $DISPLAY -rfbport 5900

- 如果没有桌面,那么需要自己建一个虚拟桌面

在服务器上:

1. 安装x11vnc以及必要dependency

sudo apt-get install x11vnc net-tools xvfb fluxbox

2. 设置$DISPLAY参数

export DISPLAY=:7 # 可以为其他数,just an example# 为了之后的方便可以写入~/.bashrc中echo export DISPLAY=:7 >> ~/.bashrcsource ~/.bashrc

3. 新建虚拟桌面

Xvfb $DISPLAY -screen 0 1920x1080x24 &fluxbox &

4. 运行x11vnc

x11vnc -display $DISPLAY -rfbport 5900

在本地上:

通过real vnc 安装VNC Reviewer,输入地址<ip>:5900 访问

测试:

在服务器上跑:

xeyes

应该能在real vnc中看到两只眼睛👀

常见问题:

1. $DISPLAY已经被使用,或者曾经被使用过

$ Xvfb $DISPLAY -screen 0 1920x1080x24(EE) Fatal server error:(EE) Server is already active for display 7        If this server is no longer running, remove /tmp/.X7-lock        and start again.(EE) 

设置$DISPLAY为其他值或者删掉/tmp/.X7-lock

rm /tmp/.X7-lock

2. x server已在运行

$ Xvfb $DISPLAY -screen 0 1920x1080x24_XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed_XSERVTransMakeAllCOTSServerListeners: server already running(EE) Fatal server error:(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE) 

删掉已有的进程

$ ps -aux | grep Xvfbuser     485583  0.0  0.1 213840 71628 pts/23   S+   19:52   0:00 Xvfb :4 -screen 0 1920x1080x24user     506709  0.0  0.0  12628  2304 pts/2    S+   20:09   0:00 grep --color=auto Xvfb
$ kill -9 485583

3. 待补充

也许您对下面的内容还感兴趣: