How to install VNC server on redhat 7

Usually we basically use xshell or putty to remote our linux server. If our linux server has a graphical interface installed, how can we use our graphical interface remotely? Now let's use vnc to implement our remote linux server

1: Install VNC Server: yum-y install vnc-server

 

2: Copy the configuration template of vnc server: CP vncserver @. service vncserver @: 1. service

[root@xwq ~]# cd /lib/systemd/system
[root@xwq system]# cp  vncserver@.service   vncserver@:1.service

Note: VNC service itself uses port 5900. Given that different users use VNC, each person's connection will get different ports. The number in the configuration file name tells the VNC server to run the service on a sub-port of 5900. In our example, the first VNC service runs on port 5901 (5900 + 1), and then on port 5900 + x. Where x refers to the following user's configuration file name vncserver@:x.service inside X.
If you want to connect with more users, you need to create configuration files and ports and add a new user and port. You need to create vncserver@:2.service and replace the user name in the configuration file with the corresponding file name and port number in the next step. Make sure that you log in to the VNC server with the user name you used when configuring the VNC password.

3:Edit the configuration template: vim vncserver@:1.service
hold root Users join the logged-in user and modify the logged-in user vnc Resolving power

//Before amendment:
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

After modification:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1376x730"
PIDFile=/home/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

4: (1)reload systemd,Scanning new or changing units: systemctl daemon-reload

[root@xwq system]# systemctl daemon-reload

(2)For landing root User adds a password

[root@xwq system]# vncpasswd root

Password:Enter your password

Verify:Enter your password again

(3)start-up vnc desktop

[root@xwq system]# vncserver :1

You will require a password to access your desktops.

Password:Enter your password

Verify:Enter your password again

xauth:  file /root/.Xauthority does not exist

xauth: (stdin):1:  bad display name "xwq:1" in "add" command

New 'xwq:1 (root)' desktop is xwq:1

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/xwq:1.log

(4)Open the service with the following command (permanent)

[root@xwq system]# systemctl enable vncserver@:1.service

//If you enter system CTL enable vncserver@:1.service The command outputs the following code.

[root@xwq system]# systemctl enable vncserver@:1.service

 ln -s '/usr/lib/systemd/system/vncserver@:1.service' '/etc/systemd/system/multi-user.target.wants/vncserver@:1.service'

  Please enter this command at the terminal: echo "127.0.0.1 xwq"> /etc/hosts

(5)Enter the following commands to configure firewall rules:

[root@xwq ~]# firewall-cmd --permanent --zone=public --add-port=5901/tcp

success

[root@xwq ~]# firewall-cmd --reload

success

5: Visit redhat successfully by installing vnc viewer on windows.

 

6: Other orders

Close the vnc service: system CTL stop vncserver @: 1. service

Disable VNC service boot: system CTL disable vncserver @: 1. service

Close the firewall: system CTL stop firewalld.service

Tags: Linux vnc firewall network

Posted on Wed, 10 Jul 2019 20:12:24 -0400 by Rabea