ssh tunneling應用案例-AWS EC2 vnc圖形化桌面的支持


一般地,無論是AWS EC2還是阿里雲的雲主機,linux系統默認都只提供ssh登錄方式。如果你是一個技術控,非常希望把圖形化界面給折騰出來,這其中就不需有vnc server的支持,除此之外,還涉及到如vnc client如何和vnc server通信的問題。 有兩個方案: 

1. 手工在安全組中開放更多的端口

2. 通過ssh隧道來橋接vnc client和server的通信鏈路

第一種方式非常容易理解,我們重點討論第2種,也就是在不開放更多端口情況下,僅使用ssh的22端口來實現vnc連接

具體地,需要以下的步驟

1. 創建好aws ec2或者阿里雲主機

2. 在windows客戶端上安裝Realvnc

3. ssh到ec2上執行以下命令(以ubutu為例子)安裝vncserver及其依賴的組件

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal xfce4 vnc4server

4.啟動vncserver,輸入vnc password

隨后編輯~/.vnc/xstartup文件並替換為以下內容:

#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &

5. 重點來了,開啟ssh的端口forwarding

ssh -L 5902:localhost:5902 -i amazon.pem ubuntu@ec2–5290172228.compute-1.amazonaws.com

再啟動vncserver

vncserver -geometry 1340x750

需要注意的是,1340x750是指的我的windows桌面次寸。隨后

6.使用Realvnc來連接localhost:5902並且輸入上面已經設置過的pasword.(there is a correlation between them (eg. display 1 = vnc port 5901, 6001 and display 2 = vnc port 5902 etc)

 

https://medium.com/@Arafat./graphical-user-interface-using-vnc-with-amazon-ec2-instances-549d9c0969c5

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM