linux远程虚拟桌面,2020-07-23 Linux 远程连接虚拟桌面
寫在前面
我的服務(wù)器為Centos7,其他 Linux 發(fā)行版可能略有差異。
此方法不需要有物理顯示屏。
可以多用戶同時(shí)登錄,同一用戶可以開啟多個(gè)虛擬桌面。
TigerVNC 安裝
使用這個(gè)軟件提供 VNC 服務(wù)。
Centos 下安裝
sudo yum install -y tigervnc-server
用戶模式開啟服務(wù)
還可以通過系統(tǒng)服務(wù)開啟,但覺得沒必要。根據(jù)誰(shuí)需要誰(shuí)開啟的原則會(huì)好一點(diǎn),安全性也高一點(diǎn)。
直接在自己的賬戶下運(yùn)行 vncserver 。第一次會(huì)要求設(shè)定密碼,后期可以通過 vncpasswd 命令可以修改密碼。第一次運(yùn)行還會(huì)初始化,在家家目錄下生成 .vnc 文件夾,里邊有 config 、localhost.localdomain:1.log localhost.localdomain:1.pid 、passwd 、xstartup 等文件。
$vncserver
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
New 'localhost.localdomain:1 (longfei)' desktop is localhost.localdomain:1
Creating default startup script /home/lo/.vnc/xstartup
Creating default config /home/lo/.vnc/config
Starting applications specified in /home/lo/.vnc/xstartup
Log file is /home/lo/.vnc/localhost.localdomain:1.log
查看運(yùn)行狀態(tài)。如果沒有其他問題,查看log文件,顯示如下。
$cat localhost.localdomain\:1.log
Xvnc TigerVNC 1.8.0 - built Nov 2 2018 19:05:14
Copyright (C) 1999-2017 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Underlying X server release 12001000, The X.Org Foundation
Fri May 22 11:27:09 2020
vncext: VNC extension running!
vncext: Listening for VNC connections on all interface(s), port 5901
vncext: Listening for HTTP connections on all interface(s), port 5801
vncext: created VNC server for screen 0
Fri May 22 11:27:13 2020
ComparingUpdateTracker: 0 pixels in / 0 pixels out
ComparingUpdateTracker: (1:-nan ratio)
設(shè)置防火墻白名單。從log文件里我們看到 VNC 連接使用的端口是5901,所以要把這個(gè)5901端口放行。當(dāng)然這個(gè)端口不是固定的,默認(rèn)從5901開始往后排,第一個(gè)用戶開啟服務(wù)是5901,第二個(gè)用戶用戶開始服務(wù)就是5902了。所以管理員可以開通5901-5910端口供用戶使用,方法不再贅述。
關(guān)閉服務(wù)。localhost.localdomain:1.pid 里邊有服務(wù)進(jìn)程號(hào),直接使用 kill 命令結(jié)束進(jìn)程就行。也可以使用 vncserver -kill :1 ,:1 就是剛才運(yùn)行的第一個(gè)服務(wù)。
遠(yuǎn)程連接。windows 端可以使用 VNC viewer 等軟件。直接輸入 ip:端口號(hào),然后提示輸入密碼就行了。
image
進(jìn)階
config
目錄下這個(gè)文件是配置文件,主要是設(shè)置一些默認(rèn)參數(shù)。但是 securitytypes=vncauth,tlsvnc 參數(shù)不要隨便設(shè)置,我copy了官方文檔里的設(shè)置,結(jié)果耗了一天時(shí)間沒有成功連通,所以不要修改默認(rèn)就好。具體參數(shù)說明參考https://tigervnc.org/doc/vncserver.html 。例如 geometry=2000x1200 設(shè)置屏幕大小等。
當(dāng)然也可以不在 config 文件里寫入默認(rèn)配置,直接在運(yùn)行 vncserver 時(shí)后面加上命令一樣的效果。
$cat config
## Supported server options to pass to vncserver upon invocation can be listed
## in this file. See the following manpages for more: vncserver(1) Xvnc(1).
## Several common ones are shown below. Uncomment and modify to your liking.
##
# securitytypes=vncauth,tlsvnc
# desktop=sandbox
# geometry=2000x1200
# localhost
# alwaysshared
xstartup
這個(gè)文件主要設(shè)置開啟的桌面。例如我的服務(wù)器上安裝了 gnome 桌面,從文檔里看我就不需要修改。如果安裝的是其他桌面程序,需要看官方文檔自行修改。
$cat xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/etc/X11/xinit/xinitrc
# Assume either Gnome or KDE will be started by default when installed
# We want to kill the session automatically in this case when user logs out. In case you modify
# /etc/X11/xinit/Xclients or ~/.Xclients yourself to achieve a different result, then you should
# be responsible to modify below code to avoid that your session will be automatically killed
if [ -e /usr/bin/gnome-session -o -e /usr/bin/startkde ]; then
vncserver -kill $DISPLAY
fi
總結(jié)
以上是生活随笔為你收集整理的linux远程虚拟桌面,2020-07-23 Linux 远程连接虚拟桌面的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 购置税减半后有4S店加价?消协回应难服众
- 下一篇: linux刷命令脚本,linux – 如