0
点赞
收藏
分享

微信扫一扫

vnc通过ssh隧道连接到Linux服务器


在deepin、ubuntu、Centos 8上测试通过。

约定

sshname表示在​​.ssh/config​​​里的名字,可以是IP地址。
注:测试用的服务器的sshname都为L1707

服务器

debian系:

sudo apt install

Centos 8:

sudo yum install

vncserver

searchstar@L1707:~$  vncserver

You will require a password to access your desktops.

Password:
Warning: password truncated to the length of 8.
Verify:
Would you like to enter a view-only password (y/n)? n

New 'X' desktop is L1707:1

Creating default startup script /home/searchstar/.vnc/xstartup
Starting applications specified in /home/searchstar/.vnc/xstartup
Log file is /home/searchstar/.vnc/L1707:1.log

客户端

先构建ssh隧道,其语法如下

ssh

个人理解:其原理是ssh登陆到​​sshname​​​这台服务器,然后以这台服务器为视角,在本地的​​xxxx​​​端口和​​ip:5901​​端口之间转发数据。相当于这两个端口变成了一个端口。

对于我们的情况,命令这样写:

ssh -g -L 5901:localhost:5901 sshname

这样就把服务器自己的5901端口映射到本地的5901端口了。

然后保持这个shell不动,另开一个shell,打开vncviewer:

sudo apt install

vnc通过ssh隧道连接到Linux服务器_linux


就是任务栏没了。。。

如果需要在终端中执行GUI程序,先查看​​DISPLAY​​环境变量是否已经设置了:

echo $DISPLAY

如果输出不为空,就可以直接在终端中执行GUI命令了:

vnc通过ssh隧道连接到Linux服务器_服务器_02


如果输出为空说明没有设置,可以手动设置一下:

export DISPLAY=:1

然后执行GUI命令后窗口就会显示在之前打开的桌面上。

xclock

vnc通过ssh隧道连接到Linux服务器_服务器_03

关闭vncserver

vncserver -kill :1

参考文献

​​http://www.zsythink.net/archives/24​​


举报

相关推荐

0 条评论