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

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

在服务器上:

sudo vim /etc/ssh/sshd_config

修改配置:

AllowAgentForwarding yes
AllowTcpForwarding yes
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost 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 >> ~/.bashrc
source ~/.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 Xvfb
user     485583  0.0  0.1 213840 71628 pts/23   S+   19:52   0:00 Xvfb :4 -screen 0 1920x1080x24
user     506709  0.0  0.0  12628  2304 pts/2    S+   20:09   0:00 grep --color=auto Xvfb
$ kill -9 485583

3. 待补充

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值