Fedora Documentation


https://docs.fedoraproject.org/en-US/Fedora/24/html/System_Administrators_Guide/ch-TigerVNC.html#s3-configuring-vnc-server


TigerVNC (Tiger Virtual Network Computing) is a system for graphical desktop sharing which allows you to remotely control other computers.
TigerVNC works on the client-server network: a server shares its output (vncserver) and a client (vncviewer) connects to the server.

Note

Unlike in Fedora 15 and Red Hat Enterprise Linux 6, TigerVNC in Fedora uses the systemd system management daemon for its configuration. The /etc/sysconfig/vncserver configuration file has been replaced by /etc/systemd/system/vncserver@.service.

9.1. VNC Server

vncserver is a utility which starts a VNC (Virtual Network Computing) desktop. It runs Xvnc with appropriate options and starts a window manager on the VNC desktop. vncserver allows users to run separate sessions in parallel on a machine which can then be accessed by any number of clients from anywhere.

9.1.1. Installing VNC Server

To install the TigerVNC server, issue the following command as root:
~]# dnf install tigervnc-server

9.1.2. Configuring VNC Server

Procedure 9.1. Configuring the first VNC connection
  1. A configuration file named /etc/systemd/system/vncserver@.service is required. To create this file, copy the /lib/systemd/system/vncserver@.service file as root:
    ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service
    
    There is no need to include the display number in the file name because systemd automatically creates the appropriately named instance in memory on demand, replacing '%i' in the service file by the display number. For a single user it is not necessary to rename the file. For multiple users, a uniquely named service file for each user is required, for example, by adding the user name to the file name in some way. See Section 9.1.2.1, “Configuring VNC Server for Two Users” for details.
  2. Edit /etc/systemd/system/vncserver@.service, replacing USER with the actual user name. Leave the remaining lines of the file unmodified. The -geometry argument specifies the size of the VNC desktop to be created; by default, it is set to 1024x768.
    ExecStart=/sbin/runuser -l USER -c "/usr/bin/vncserver %i -geometry 1280x1024"
    PIDFile=/home/USER/.vnc/%H%i.pid
    
  3. Save the changes.
  4. To make the changes take effect immediately, issue the following command:
    ~]# systemctl daemon-reload
  5. Set the password for the user or users defined in the configuration file. Note that you need to switch from root to USER first.
    ~]# su - USER
    ~]$ vncpasswd
    Password:
    Verify:
    

    Important

    The stored password is not encrypted; anyone who has access to the password file can find the plain-text password.

9.1.2.1. Configuring VNC Server for Two Users

If you want to configure more than one user on the same machine, create different template-type service files, one for each user.
  1. Create two service files, for example vncserver-USER_1@.service and vncserver-USER_2@.service. In both these files substitute USER with the correct user name.
  2. Set passwords for both users:
    ~]$ su - USER_1
    ~]$ vncpasswd
    Password:
    Verify:
    ~]$ su - USER_2
    ~]$ vncpasswd
    Password:
    Verify:
    

9.1.3. Starting VNC Server

To start or enable the service, specify the display number directly in the command. The file configured above in Procedure 9.1, “Configuring the first VNC connection” works as a template, in which %i is substituted with the display number by systemd. With a valid display number, execute the following command:
~]# systemctl start vncserver@:display_number.service
You can also enable the service to start automatically at system start. Then, when you log in, vncserver is automatically started. As root, issue a command as follows:
~]# systemctl enable vncserver@:display_number.service
At this point, other users are able to use a VNC viewer program to connect to the VNC server using the display number and password defined. Provided a graphical desktop is installed, an instance of that desktop will be displayed. It will not be the same instance as that currently displayed on the target machine.

9.1.3.1. Configuring VNC Server for Two Users and Two Different Displays

For the two configured VNC servers, vncserver-USER_1@.service and vncserver-USER_2@.service, you can enable different display numbers. For example, the following commands will cause a VNC server for USER_1 to start on display 3, and a VNC server for USER_2 to start on display 5:
~]# systemctl start vncserver-USER_1@:3.service
~]# systemctl start vncserver-USER_2@:5.service

9.1.4. Terminating a VNC Session

Similarly to enabling the vncserver service, you can disable the automatic start of the service at system start:
~]# systemctl disable vncserver@:display_number.service
Or, when your system is running, you can stop the service by issuing the following command as root:
~]# systemctl stop vncserver@:display_number.service

原文地址:https://www.cnblogs.com/ztguang/p/12645905.html