系统相关
首页 > 系统相关> > Linux - TigerVNC Configure

Linux - TigerVNC Configure

作者:互联网

VNC

Virtual Network Computing (VNC) 是一个图形化桌面共享系统, 可以远程连接计算机, 使用键盘和鼠标.

本文包含 在RHEL8上,安装和配置 VNC server 的步骤  . 我们还会展示如何通过SSH通道安全的连接.

 

Prerequisites

To follow this guide, you need to be logged in as a user with sudo privileges on your remote CentOS machine.

Installing Desktop Environment

Generally, servers don’t have a desktop environment installed. If the machine you want to connect to doesn’t have GUI, the first step is to install it. Otherwise, skip this step.

Run the following command to install Gnome, the default desktop environment in CentOS 8 on your remote machine:

sudo dnf groupinstall "Server with GUI"

Depending on your system, downloading and installing the Gnome packages and dependencies may take some time.

Installing VNC Server

TigerVNC is an actively maintained high-performance open-source VNC server. It is available in the default CentOS repositories. To install it, type:

sudo dnf install tigervnc-server

Configuring VNC Server

In CentOS 8, TigerVNC is configured using the systemd daemon.

In this example, we’ll show you how to configure TigerVNC for one or more VNC users.

  1. Use the vncpasswd command to set up the password. Run the command as the user that will access the VNC server, do not use sudo:

    vncpasswd

    You will be prompted to enter and confirm the password and whether to set it as a view-only password. If you choose to set up a view-only password, the user will not be able to interact with the VNC instance with the mouse and the keyboard.

    The first time the vncpasswd command is run, it will create and store the password file in the user’s ~/.vnc directory.

    Password:
    Verify:
    Would you like to enter a view-only password (y/n)? n
    A view-only password is not used
    

    If you’re adding a second user, switch to it and set the password with vncpasswd.

  2. The next step is to configure TigerVNC to use Gnome. VNC reads the user configuration settings from the ~/.vnc/config file. Open the file and add the following:

    vim ~/.vnc/config
    session=gnome
    geometry=1920x1200
    localhost
    alwaysshared
    

    The session option specifies the session you want to start, and the geometry option specifies the size of the VNC desktop.

    Save and close the file . If you’re adding multiple users, repeat the same step.

  3. TigerVNC ships with a file that allows you to map a user to a particular port. The mapping is configured in the /etc/tigervnc/vncserver.users file:

    sudo vim /etc/tigervnc/vncserver.users

    The file uses <display_port>=<username> syntax. In the example below, we are mapping display port :1 to user linuxize. Use the same format to add more users.

    # TigerVNC User assignment
    #
    # This file assigns users to specific VNC display numbers.
    # The syntax is <display>=<username>. E.g.:
    #
    # :2=andrew
    # :3=lisa
    :1=linuxize
    

    :1 is the display port number on which the VNC server will run. In our case, the server is running on TCP port 5901 (5900+1). If you map another user, for example, to display port :2, the server will also listen on port 5902 (5900+2).

    What is important to understand is that when working with VNC servers, :X is a display port that refers to 5900+X.

Starting the Tigervnc Server

Once you’re done with the configuration, the last step is to start the VNC server.

To start and enable the VNC service for the user mapped to the display port :1, enter:

sudo systemctl enable vncserver@:1 --now

The VNC server will listen on port 5901, as we discussed in the previous section.

You can verify that the service is successfully started with:

sudo systemctl status vncserver@:1
● vncserver@:1.service - Remote desktop service (VNC)
   Loaded: loaded (/usr/lib/systemd/system/vncserver@.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-12-17 21:49:41 UTC; 8s ago
  ...

To enable VNC for other users, simply replace 1 with the display port mapped to the user.

Connecting to VNC server

VNC is not an encrypted protocol and can be subject to packet sniffing. The recommended approach is to create an SSH tunnel to securely forward traffic from your local machine on port 5901 to the remote server on the same port.

Set Up SSH Tunneling on Linux and macOS

If you run Linux, macOS, or any other Unix-based operating system on your machine, you can easily create a tunnel using the following ssh command:

ssh -L 5901:127.0.0.1:5901 -N -f -l username remote_server_ip

You will be prompted to enter the user password.

Do not forget to replace username and server_ip_address with your username and the IP address of your server.

Set Up SSH Tunneling on Windows

Windows users can set up SSH Tunneling using PuTTY .

 

 

Open Putty and enter your server IP Address in the Host name or IP address field.

  VNC Putty

Under the Connection menu, expand SSH and select Tunnels. Enter the VNC server port (5901) in the Source Port field, enter server_ip_address:5901 in the Destination field and click on the Add button as shown in the image below:

  VNC SSH Tunnel Putty

Go back to the Session page to save the settings so that you do not need to enter them each time. To login to the remote server, select the saved session and click on the Open button.

Connecting using Vncviewer

To connect to the remote Server, open your VNC viewer, and enter localhost:5901.

You can use any VNC viewer such as TigerVNC, TightVNC, RealVNC, UltraVNC, Vinagre, and VNC Viewer for Google Chrome .

We’re using TigerVNC:

  VNC Viewer

Enter the password when prompted, and you should see the default Gnome desktop. It should look something like this:

  VNC Desktop

That’s it! You can now start working on your remote desktop from your local machine using your keyboard and mouse.

Conclusion

We’ve shown you how to set up a VNC server and connect to a remote CentOS 8 machine.

Feel free to leave a comment if you have any questions.

 

环境

问题

决议

For RHEL 8.3+ (tigervnc-server-1.10.1-7.el8) please see Are there any changes to the default vncserver configuration in RHEL8.3.0?

Automatic Configuration

Red Hat Access Labs provides a VNC Configurator tool for automatically generating a VNC configuration based on your environment and deployment goals. The VNC Configurator incorporates the information included in this document but makes it easier to generate valid and support-recommended configurations.

Note: This tool can not be used for RHEL8.

Manual Configuration Details

Installing the basic VNC service

Configuring the VNC service

Enable and start the vnc service:

Configuring Desktop Environment:

For Gnome
For KDE

Connecting with a VNC client:

 

 

 SOLUTION 已验证 - 已更新 2020年十二月25日12:16 -  English 

环境

问题

决议

Install the required packages

To install the required packages, run the following command as root:

Raw
# yum -y install tigervnc-server tigervnc

Note: If a graphical desktop environment is not already installed, please refer to: How to install a graphical interface in Red Hat Enterprise Linux

Changes in the Tigervnc server configuration files

The vncserver configuration file's location has changed in the latest version of tigervnc-server. The default configuration files are now available in the /etc/tigervnc/ directory. There are three main files in this directory:

Add a user mapping in /etc/tigervnc/vncserver.users

With this option the administrators can map a user to a particular port. The mapping should be done in /etc/tigervnc/vncserver.users configuration file.

Raw
:x=user    

For example:

Raw
:1=vncuser1
:2=vncuser2

Note:- Red Hat Enterprise Linux only supports one unique user per GUI session per unique system. Therefore, use one vnc session per user. Do not configure multiple vnc session for single user. For details, refer: How many GUI sessions can I log a user into?

Configure Xvnc options

To configure Xvnc parameters, open vncserver-config-defaults configuration file. This file is for the default Xvnc configuration and will be applied to every user unless any of the following applies:

The format of the configuration file is also quite simple as the configuration is as below:

Raw
    option=value

For example:

Raw
    session=gnome
    #securitytypes=vncauth,tlsvnc 
    #desktop=sandbox
    #geometry=2000x1200
    #localhost
    #alwaysshared

Note:- The only required parameter here is session=. It should match the name of a session desktop file from /usr/share/xsessions directory. The default option here for supported deployments will be session=gnome. Please see relevant documentation for any third party/upstream GUIs provided by the vendor/community.

Set vnc password

Set a password for each user in order to be able to start the Tigervnc server. In order to create a password, run the following command as the user you will be starting the server for.

Raw
$ vncpasswd

Note:- This must be set while logged in as the user. You cannot set this as root/other administrators with the command vncpasswd username command in RHEL 8.

If vncserver was previously used on the system, make sure the $HOME/.vnc folder created by vncpasswd have the correct SELinux context. There are two possible options to ensure that:

Start the Tigervnc server

Finally start the server using systemd service. To do so just run,

Raw
As root user:
# systemctl start vncserver@\:$x.service

As non-root user:
$ sudo systemctl start vncserver@\:$x.service

Replace the $x by the actual number configured in /etc/tigervnc/vncserver.users.

Raw
$ sudo systemctl start vncserver@\:1.service

It will start a Tigervnc server for user vncuser1 with a GNOME session.

Note:- If you are utilizing vino (screen sharing), note that it shares ports with VNC. Do not utilize any ports that may cause a conflict. To determine what vino port may be used by a given user, have that user run 'gsettings get org.gnome.desktop.remote-access alternative-port` while logged in to the local graphical console.

Configure the firewall to accept incoming connections

Execute the following command to open VNC ports in the firewall.

Raw
# firewall-cmd --permanent --zone=public --add-port 5901/tcp

This command only opens TCP port 5901 for incoming connections. The same command can also be used to open additional ports when required. You may need to consider rich rules for your use case. The above is merely a generic rule that will open up blanket access to port 5901, or whichever port was specified.

Reload the firewall to make firewall rules effective

Raw
# firewall-cmd  --reload

Note:-

Limitations:-

根源

The previous Tigervnc versions had a wrapper script called vncserver which could be run as a user manually to start Xvnc process. The usage was quite simple as can be started by executing the following command:

Raw
$ vncserver :x [vncserver options] [Xvnc options]

While this was working just fine, there were issues when users wanted to start a Tigervnc server using systemd. For these reasons things were completely changed and there is now a new way how this all is supposed to work.

There are additional updates to SELinux policy that require that the policy be updated as well, otherwise the VNC Server will not start on older point releases. Mixing SELinux policy packages from newer point releases on to older point releases is subject to cause additional problems. Best practice will be to fully update if you wish to use the aforementioned version of tigervnc.

 

 

参考:

[1]  How to Install and Configure VNC on CentOS 8

[2]  How to configure Virtual Network Computing (VNC) in Red Hat Enterprise Linux 7/8 - 8.2?

[3]  Are there any changes to the default vncserver configuration in RHEL8.3?

标签:VNC,Configure,server,Raw,TigerVNC,user,file,Linux,vncserver
来源: https://www.cnblogs.com/firestar277/p/14672432.html