1. 程式人生 > >Windows遠程桌面連接CentOS 7

Windows遠程桌面連接CentOS 7

uic ant script multi quic AR 沒有 RF ria

1. 安裝tigervnc-server

yum install tigervnc-server

2. 設置vncserver服務器

將默認提供的文件復制到/etc/systemd/system,命令如下:

cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service

修改配置

vi /etc/systemd/system/vncserver@:1.service

將其中<USER>替換為你想要的用戶名,本人使用的賬號為root,添加設置分辨率的參數-geometry 1280x720

,所有內容如下

# The vncserver service unit 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` # . . . [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=/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1280x720" PIDFile=/root/.vnc/%H%i.pid # 普通用戶可能路徑為 /home/<USER>/.vnc/%H%i.pid ExecStop=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : [Install] WantedBy=multi-user.target

重新加載配置:

systemctl daemon-reload

如果需要可以設置成開機啟動:

systemctl enable vncserver@:1.service

3. 設置防火墻

首先判斷firewalld是否啟動

firewall-cmd --state

如果沒有啟動,先啟動防火墻

systemctl start firewalld

添加端口號5901-5905例外

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

重新加載防火墻

firewall-cmd --reload

可以使用下面命令查看端口號是否被加入

firewall-cmd --list-all-zones

4. 設置VNC密碼

通過ssh,用oracle用戶名登錄到服務器,執行下面命令

vncserver

終端會提示你輸入密碼,如下

You will require a password to access your desktops.

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

New lenmomDesktop:1 (root) desktop is lenmomDesktop:1

Creating default startup script /root/.vnc/xstartup
Creating default config /root/.vnc/config
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/lenmomDesktop:1.log

如果想修改密碼,可以使用vncpasswd。現在已經有一個vnc服務在運行了,但我們需要使用剛剛配置的服務來啟動,所以我們需要先殺死剛剛的vnc服務,使用下面命令:

vncserver -kill :1

接下來,重啟服務:

systemctl daemon-reload
systemctl restart vncserver@:1.service

使用下面命令查看該服務是否正確運行

systemctl status vncserver@:1.service -l

如果正確啟動,輸出應為:

vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@:2.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2017-07-23 21:55:35 CST; 12h ago
Process: 8720 ExecStart=/usr/sbin/runuser -l oracle -c /usr/bin/vncserver %i -geometry 1280x720 (code=exited, status=0/SUCCESS)
Process: 8716 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 8744 (Xvnc)
 CGroup: /system.slice/system-vncserver.slice/vncserver@:2.service
   ? 8744 /usr/bin/Xvnc :2 -desktop 127.0.0.1:2 (oracle) -auth /home/oracle/.Xauthority -geometry 1280x720 -rfbwait 30000 -rfbauth /home/oracle/.vnc/passwd -rfbport 5902 -fp catalogue:/etc/X11/fontpath.d -pn
7月 23 21:55:32 127.0.0.1 systemd[1]: Starting Remote desktop service (VNC)...
7月 23 21:55:35 127.0.0.1 systemd[1]: Started Remote desktop service (VNC).

如果想配置多用戶同時訪問,需要將上面vncserver@:1.service,改為vncserver@:2.service,然後配置其中用戶名、分辨率參數,再按上述步驟做一遍。

Windows遠程桌面連接CentOS 7