轉載請註明來源:http://blog.csdn.net/greenlight_74110/article/details/78623025
Windows/Linux 遠程桌面訪問CentOS
進入root
su
安裝xrdp和vnc-server
yum install -y xrdp vnc-server
編輯 vncservers
在文件的末尾添加如下兩行:
vim /etc/sysconfig/vncservers
VNCSERVERS="1:john"
VNCSERVERARGS[1]="-geometry 1280x720"
VNCSERVERS="2:july"
VNCSERVERARGS[2]="-geometry 800×600 -depth 24 -nolisten tcp -nohttpd -localhost"
說明:
VNCSERVERS 這一行是配置在系統啓動時啓動幾個 VNC server,上面的例子裏運行了三個 VNC server,其中 john 在 display :1(對應於5901),july 在 display :2(對應於5902)。訪問時使用xxx.xxx.xxx.xx:1或者xxx.xxx.xxx.xx:2訪問即可。
VNCSERVERARGS 這三行,分別爲 VNC server 1, 2配置啓動參數,上面的例子裏對 john 使用屏幕分辨率 1024×768,對 july 使用 800×600,24 色,不支持 tcp,不支持 http 連接,只能在本地測試訪問。
編輯 /etc/group 文件
授予用戶登錄權限:
vim /etc/group
假設允許用戶“john”、“cat”遠程登錄,禁止用戶“pig”遠程登錄。在文件末尾處添加:
john:250:john
cat:x:250:cat
pig:x:501:
設置用戶遠程登錄密碼
首先要回到相應的用戶權限下。
獲得相應用戶的權限:
su john
設置用戶遠程登錄密碼:
vncpasswd
注:每個授予遠程登錄權限的用戶,都要完成此項操作!
設置防火牆
在iptables中添加端口列外
-A INPUT -p tcp -m tcp --dport 5901:5903 -j ACCEPT #for the vncserver
-A INPUT -m state --state NEW -m tcp -p tcp--dport 3389 -j ACCEPT #for the xrdp
(option)或者也可以關閉防火牆
(option)查看防火牆狀態
service iptables status
(option)關閉防火牆
service iptables stop
chkconfig off
(option)或者直接將服務器上的防火牆刪除
chkconfig --del iptabels (服務內刪除iptables)
完成以上操作後需要重啓防火牆
service iptables restart
加入開機自啓
設置讓 xrdp 和 vncserver 隨開機加載啓動。
chkconfig xrdp on
chkconfig vncserver on
維護vncserver
- 打開/關閉端口
vncserver :1
vncserver -kill :1
- 其它
service vncserver status
service vncserver start
service vncserver stop
service vncserver restart
維護xrdp
service xrdp status
service xrdp start
service xrdp stop
運行如下命令,可以看到3389端口:
netstat -tnlp |grep xrdp
遠程登錄
windows下在“運行”中輸入mstsc,即可打開遠程連接程序
linux下用remote desktop client且訪問方式設置爲xrdp,直接輸ip地址即可訪問。但如果要用vncviewer,記得在ip地址後面加端口號(可以是1,2….也可以是5901,5902,….)。