在deepin、ubuntu、Centos 8上测试通过。
约定
sshname表示在.ssh/config
里的名字,可以是IP地址。
注:测试用的服务器的sshname都为L1707
服务器
debian系:
sudo apt install tightvncserver
Centos 8:
sudo yum install tigervnc-server.x86_64
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 -g -L xxxx:ip:5901 sshname
个人理解:其原理是ssh登陆到sshname
这台服务器,然后以这台服务器为视角,在本地的xxxx
端口和ip:5901
端口之间转发数据。相当于这两个端口变成了一个端口。
对于我们的情况,命令这样写:
ssh -g -L 5901:localhost:5901 sshname
这样就把服务器自己的5901端口映射到本地的5901端口了。
然后保持这个shell不动,另开一个shell,打开vncviewer:
sudo apt install xtightvncviewer
vncviewer localhost:1
就是任务栏没了。。。
如果需要在终端中执行GUI程序,先查看DISPLAY
环境变量是否已经设置了:
echo $DISPLAY
如果输出不为空,就可以直接在终端中执行GUI命令了:
如果输出为空说明没有设置,可以手动设置一下:
export DISPLAY=:1
然后执行GUI命令后窗口就会显示在之前打开的桌面上。
xclock
关闭vncserver
vncserver -kill :1
参考文献
http://www.zsythink.net/archives/2450
https://blog.csdn.net/cuma2369/article/details/107668471