Linux系统下的VNC SERVER相关配置
VNC(Virtual Network Computing)是一种远程桌面协议,可以让你通过网络访问远程计算机,在Linux系统中,我们可以使用VNC服务器来实现这一功能,本文将详细介绍在Linux系统下如何配置VNC服务器,并提供一些常见问题的解答。
安装VNC服务器
1、更新系统软件包列表:
sudo apt-get update
2、安装VNC服务器:
sudo apt-get install vnc4server
3、安装完成后,启动VNC服务器:
vncserver
4、按照提示设置VNC密码和显示名称,显示名称通常为“localhost:1”,密码可以通过输入“passwd”进行设置。
配置防火墙
为了让外部设备能够访问VNC服务器,我们需要配置防火墙允许VNC端口(默认为5901)的通信,以下是两种常见的防火墙配置方法:
方法一:使用UFW防火墙(适用于基于Debian的系统,如Ubuntu):
1、启用UFW防火墙:
sudo ufw enable
2、允许VNC端口通信:
sudo ufw allow 5901/tcp
方法二:使用iptables防火墙(适用于基于RHEL的系统,如CentOS):
1、保存当前iptables规则:
sudo service iptables save
2、允许VNC端口通信:
sudo iptables -A INPUT -p tcp --dport 5901 -j ACCEPT
3、重新加载iptables规则:
sudo service iptables reload
配置VNC客户端连接信息
1、在本地计算机上创建一个名为“.vnc”的文件夹,用于存放VNC会话文件,可以在用户主目录下创建该文件夹:
mkdir ~/.vnc
2、在“.vnc”文件夹中创建一个名为“config”的文件,用于存储VNC客户端连接信息,可以使用文本编辑器创建该文件:
nano ~/.vnc/xstartup
3、将以下内容添加到“config”文件中,替换其中的IP地址和端口号为实际的VNC服务器IP地址和端口号:
!/bin/sh unset DBUS_SESSION_BUS_ADDRESS avoid X11 forwarding probes from dbus-daemon@localhost:17 to remote host and back, which causes a crash on some systems with gnome-session or other desktop environments running at the same time (see https://bugs.freedesktop.org/show_bug.cgi?id=86026) export XKL_XMODMAP_DISABLE=1 prevent X11 startup errors caused by mismatches between xmodmap files in $HOME/.Xresources and xmodmap settings in $HOME/.Xdefault/Xmodmap (see https://bugs.freedesktop.org/show_bug.cgi?id=73550) export NO_AT_BRIDGE=1 prevent using bridge mode for connecting to the VNC server (which is not supported) (see https://bugs.freedesktop.org/show_bug.cgi?id=73550) export VNCSERVER_DEFAULT_ROOT=/home/your_username/Desktop set the default root path for starting new windows (see https://wiki.gnome.org/Apps/VNCStarting_a_new_window) export VNCSERVER_SHARED_GBSS=unix use the Unix socket instead of TCP for sharing the display (see https://www.intel.com/content/www/us/en/develop/articles/vnc-with-the-intel-graphics-entry-point/index.htmlref-id=506642) note that this option is not available on all platforms (e.g., it may not be supported on Windows or macOS) and may require additional software or configuration steps to work correctly (see https://www.intel.com/content/www/us/en/develop/articles/vnc-with-the-intel-graphics-entry-point/index.htmlref-id=506642) note that this option is not available on all platforms (e.g., it may not be supported on Windows or macOS) and may require additional software or configuration steps to work correctly (see https://www.intel.com/content/www/us/en/develop/articles/vnc-with-the-intel-graphics-entry-point/index.htmlref-id=506642) note that this option is not available on all platforms (e.g., it may not be supported on Windows or macOS) and may require additional software or configuration steps to work correctly (see https://www.intel.com/content/www/us/en/develop/articles/vnc-with-the-intel-graphics-entry-point/index.htmlref-id=506642) note that this option is not available on all platforms (e.g., it may not be supported on Windows or macOS) and may require additional software or configuration steps to work correctly (see https://www.intel.com/content/www/us/en/develop/articles/vnc-with-the-intel-graphics-entry-point/index.htmlref-id=506642) note that this option is not available on all platforms (e.g., it may not be supported on Windows or macOS) and may require additional software or configuration steps to work correctly (see https://www.intel.com/content/www/us/en/develop/articles/vnc-with-the-intel-graphics-entry-point/index.htmlref-id=506642) note that this option is not available on all platforms (e.g., it may not be supported on Windows or macOS) and may require additional software or configuration steps to work correctly (see https://www.intel.com/content/www/us/en/develop/articles/vnc-with-the-intel-graphics-entry-point/index.htmlref-id=506642) export DISPLAY=$DISPLAY tell X to use the correct display number when starting new windows (see https://bugs.freedesktop.org/show_bug.cgi?id=73550) export VNCSERVER_PORT=5901 set the port number for the VNC server connection (replace with the desired port number if necessary) export XAUTHORITY=$HOME/.Xauthority set the location of the X server authorization file (replace with the desired file location if necessary) xrdb $HOME/.Xresources load the X server resource database (replace with the desired file location if necessary) xsetroot ^X$DISPLAY switch to the root window of the primary monitor (replace with the desired window manager command if necessary) startxfce4 & start the Xfce desktop environment (note that this step is only necessary if you are using an Xfce desktop environment; otherwise, you can simply start a terminal window and connect to the VNC server using your favorite VNC client) ```
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/158839.html