Xubuntu 18.04 配置x11vnc,修改分辨率,远程访问流畅

By | 2019年9月14日

一、说明

这篇文章记录自己一次简单的配置过程,如果你有同样的需求,欢迎你尝试我的方法。

我的xubuntu安装在虚拟机中,作为开发机,所以单单ssh远程控制,对我来说还是不够的。

Xubuntu=Ubutun+Xfce(桌面管理工具),Xfce非常轻巧简洁,但是该有的都有,最重要的是VNC远程操作的时候非常流畅。

我也曾在Ubuntu的Gnome桌面配置x11vnc,但是访问卡顿很厉害。后来通过vncserver+fxce来实现远程访问,流畅度很好,但是可能因为fxce和gnome冲突或者其他原因,导致vncserver+fxce会出现一些问题,比如远程的时候程序无法打开。

最后,我干脆就直接安装了Xubuntu,加上x11vnc!x11vnc可以直接绑定显示器,就是说vnc进去的桌面和显示器上的是同步的。

二、环境配置

2.1、通过命令行安装x11vnc

sudo apt-get install x11vnc

2.2、设置vnc密码

x11vnc -storepasswd

执行该命令之后,会要求输入两次vnc密码,最后确认是否将密码配置写入当前用户家目录的/.vnc/passwd文件中,我们输入y进行确认

2.3、复制该配置文件到/etc/x11vnc.pass,并赋予可读权限

这一步可以不用做,主要是为了方便

sudo cp /home/您的用户名/.vnc/passwd /etc/x11vnc.pass 
sudo chmod +r /etc/x11vnc.pass

2.4、运行测试

运行如下命令,并通过vnc客户端访问该主机5900端口进行访问测试

x11vnc -forever -shared -rfbauth /etc/x11vnc.pass

2.5、设置开机自动启动

sudo vi /lib/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 /etc/x11vnc.pass -rfbport 5900 -shared 
 
[Install] 
WantedBy=multi-user.target

设为开机启动

sudo systemctl daemon-reload
sudo systemctl enable x11vnc.service
sudo systemctl start x11vnc.service

2.6、重启测试

sudo reboot

三、远程修改分辨率

如果机器上没有连接显示器的话,那么在settings->display菜单里面是没有办法修改的。我们可以通过下面两种方式修改:

方法一:/etc/X11/xorg.conf 配置文件

创建配置文件 /etc/X11/xorg.conf

sudo vim /etc/X11/xorg.conf #创建配置文件

文件内容:

Section "Device"
        Identifier "Configured Video Device"
EndSection

Section "Monitor"
        Identifier "Configured Monitor"
EndSection

Section "Screen"
        Identifier "Default Screen"
        Monitor "Configured Monitor"
        Device "Configured Video Device"
        SubSection "Display"
                   Depth 24
                   Virtual 1680 1050
        EndSubSection
EndSection

可以将内容中的 1680 1050 修改为你需要的分辨率,配置完成后请重启操作系统

方法二:使用xrandr命令

xrandr --fb 1280x1024  #1280x1024为分辨率,中间是字母“x”

四、参考

参考的连接原文我找不到了,我当时看到一篇文章,感觉这个答主的方案可行,我就复制下来了。原文如下:

v_dragon, My personal preference is to use x11vnc rather then any of the VNC derivatives like tightVNC or vino.

x11vnc will show your real desktop (on display 0.) the others create a new desktop (display :1 for example) and they don’t get setup with your icons or anything. They don’t even get an application bar. I have tried them and having a blank desktop is basically useless.

I am recalling these instructions from memory, so some experimentation may be needed,

In a terminal do: apt-get x11vnc, or use the synaptic package manager.

Once installed, to run the server, I enter the following:

x11vnc -display :0 -24to32 -usepw -forever

I have made a script called start_x11vnc and the line reads:

/usr/bin/x11vnc -display :0 -24to32 -usepw -forever

The extra path info is needed because I intend to run this script before logging in and there is no default path at that point.

the -display :0 tells the server to show your desktop, not make a new fresh empty one

My video screen is low res, so I need the -24to32 to get vnc viewers to work.

the -usepw tells it to use the password you previously created for VNC logins. if there is none, it will ask you for one, make it, and won’t ask again.

The -forever option tells x11vnc not to quit when the user logs out (this will allow you to log back in later without having to restart the server.)

I hope this helps you.

Now if I could only get this server to startup automatically when I boot the computer, preferably before the login screen appears.

I am still working on that.

Mark.
Last edited by Cool Javelin; December 15th, 2008 at 08:55 PM. Reason: typeo’s

发表评论