RHEL7中tiger VNC的配置和使用

簡介:

Tigervnc 是一個遠程桌面共享和控制工具

tigervnc 是client-server的工作模式,默認是不加密的,可以使用ssh forwarding map來加密這個連接

在rhel7之前tigervnc的配置文件被放在/etc/sysconfig/ 文件夾中

在rhel7中其配置文件放在/etc/systemd/system/ 中

每個用戶對應個配置文件,文件名如:vncserver-root (rhel7之前)  [email protected](rhel7)

vncserver 是一個能開啓vnc桌面的工具,它會使用適當選線來運行Xvnc 並在vnc 桌面上運行一個window manager。

vncserver允許多個會話同時並行訪問一臺主機,允許多個用戶從任何地方訪問某臺主機

服務端安裝:

yum install tigervnc-server

客戶端安裝:

yum install tigervnc

配置:

示例配置文件是 /lib/systemd/system/[email protected] 內容如下:

[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 <USER> -c "/usr/bin/vncserver %i [-geometry size ]"            //<USER>可以使用具體的用戶名替換掉,一旦這個服務開啓這個用戶就可以登錄了,%i,代表的是window號碼,這個號碼是唯一,systemd會自動根據用戶在啓動該unit時指定的window號碼來替換。  -geometry size: 指定桌面分辨率,如果不指定,則size默認爲1024*768

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

******可以爲多個用戶創建多個 unit file,然後給它們一個唯一名,並放到 /etc/systemd/system中,當某個用戶需要使用遠程桌面時,就啓動對應的unit file。

文件配置完成後,需要重新整理systemd依賴關係,只要修改了unit file就要重新整理:

systemctl  daemon-reload

 修改vnc連接的密碼:

su - username

vncpasswd 

密碼必須設置否則無法登陸

啓動:

systemctl start vncserver-username@:window_number.service

開機就啓動某個window

systemctl enable vncserver-username@:window_number.service

客戶端連接:

客戶端程序vncviewer

輸入vncserver地址和窗口號:vncserver:window_number

輸入vnc-password

爲 vnc 配置防火牆:

使用非加密的鏈接,默認會被firewalld blocked 掉,想要 vnc正常工作就需要讓firewalld開放相應的端口才行。

vnc默認的端口號爲5900,而每個vnc window的端口號是: 5900+window_number(or,display_number)

如:systemctl start vncserver-username@:2.service  那麼這個vnc window的端口號就是 5902

設置:

firewall-cmd --list-all   //查看防火牆規則

firewall   --add-rich-rule='rule family="ipv4" source address="client_ip" service name=service_name accept'    //[--permanent] 指定是否永久生效, --zone指定將該rule放到哪個zone當中,這樣從這個地址來的任何流量都可以通過!!

也可以只打開指定端口:

firewall-cmd --zone=public --add-port=590*/tcp

使用ssh連接:

vncviewer -viausername@vncserver  localhost:window_number   (使用 ssh forwarding)//localhost一定要加,否則無法連接

避免使用不安全的鏈接:

將unit file中的 ExecStart=/sbin/runuser -l user -c "/usr/bin/vncserver -localhost %i" 

-localhost 參數可以讓vncserver不接受 除本機及ssh forwarding 以外的任何連接。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章