Centos7 remote desktop vnc/vnc-server settings, worth recommending

Centos7 remote desktop vnc/vnc-server settings
2014-08-26 19:08:16

Original work, reprinting is allowed, please be sure to indicate the original source of the article, author information and this statement in the form of hyperlinks when reprinting. Otherwise held liable. http://uchase.blog.51cto.com/880483/1545357

Centos7 is very different from Centos6.x.
In order to install a remote desktop on a server, I took a lot of detours. This blog post is written purely for the record. If you encounter the same problem in the future, you can trace it back.

1. Assuming that your system does not have any vnc software installed, first install vnc

yum -y install tigervnc-server tigervnc

2. For systems before Centos7, if you install vnc, you generally need to configure

[root@localhost ~]# cat /etc /sysconfig/vncservers
# THIS FILE HAS BEEN REPLACED BY /lib/systemd/system/[email protected]
However, as mentioned above, Centos7 needs to configure the files in
[root@localhost ~]# ll /lib/systemd/system/vncserver @.service
-rw-r--r--. 1 root root 1744 Jun 10 14:15 /lib/systemd/system/[email protected]

3. There are the following tips in the file

# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
# 2. Edit <USER> and vncserver parameters appropriately
# ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service

4. Copy a file and rename it to vncserver@:1.service

[ root@localhost ~]# cp /lib/systemd/system/[email protected] /lib/systemd/system/vncserver@:1.service

5. Replace <User> in the file with your current user, and replace %i Replace with 1

[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 :1 > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver : 1 -geometry 1280x720 -depth 24"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill :1 > /dev/null 2>&1 | | :'
[Install]
WantedBy=multi-user.target

6. Update systemctl

systemctl daemon-reload

7. Set to automatically start

systemctl enable vncserver@:1.service

8. Start vnc service

systemctl start vncserver@:1.service

9. Add the corresponding port 5901 to iptables (note that if there are other users, you need to add the port as well. The default port of vnc is 5900 + n)

[root@localhost system]# cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

注意:
1. If you do not configure and enable the firewall, if you use VNC Viewer to connect at this time, it will report: "connect: Connection timed out (10060)" error.
2. This article takes the root user as an example. If other users also need to log in, then the file needs to be copied as
cp /lib/systemd/system/[email protected] /lib/systemd/system/vncserver@:2.service
At the same time, change %i in the file to 2, and create a vncpasswd for the corresponding user.
3. You can access through UltraVNC, TigerVNC or RealVNC Viewer, I can connect using these 3 tools under win7

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326945707&siteId=291194637