通过ssh远程重启vnc_如何通过SSH隧道使用VNC远程控制Linux服务器

通过ssh远程重启vnc

Sometimes we need to have the GUI of some application on the remote server. ssh’s X11 forwarding with “-X” parameter is a good and fast method. But if we want to have a whole desktop environment, vnc is a good choice. In this post, the method of how to control remote server using vnc through a ssh tunnel is instructed. By using the ssh tunnel, the communication between the client and the server is encrypted. And under some condition we can only use the port 22 of the server, so this method is more valuable.

有时我们需要在远程服务器上具有某些应用程序的GUI。 带有“ -X”参数的ssh的X11转发是一种很好且快速的方法。 但是,如果我们要拥有一个完整的桌面环境,那么vnc是一个不错的选择。 本文介绍了如何通过ssh隧道使用vnc控制远程服务器的方法。 通过使用ssh隧道,客户端和服务器之间的通信被加密。 在某些情况下,我们只能使用服务器的端口22,因此此方法更有价值。

The default window manager of vncserver is twm. If you want to use gnome please refer to here.

vncserver的默认窗口管理器是twm。 如果要使用gnome,请参考此处

ssh’s port forwarding function give us the convenient way to do this.

ssh的端口转发功能为我们提供了方便的方法。

1)连接到服务器,并同时设置端口转发ssh隧道 (1) Connect to the server and meantime set up the port forwarding ssh tunnel)

Suppose we use port 1111 on localhost for the remote control and the remote vnc server is the first one so the default port is 5901 on the server. We need to forward port 1111 on locahost to 5901 of the remote server. The command is like this:

假设我们使用本地主机上的端口1111进行远程控制,并且远程vnc服务器是第一个,因此服务器上的默认端口为5901。 我们需要将locahost上的端口1111转发到远程服务器的5901。 该命令是这样的:

ssh -L 1111:localhost:5901 username@vnc_server

This ssh tunnel works in this way: when a packet goes to port 1111 on localhost, this packet is forwarded to sshd running on the vnc_server, then the sshd running on the vnc_server forwards this packet to localhost:5901 that is the port 5901 on itself (vnc_server). The response packet follows the opposite of the path. So port 1111 of localhost can be regarded as the port 5901 on vnc_server.

该ssh隧道以这种方式工作:当数据包到达localhost上的端口1111时,该数据包被转发到在vnc_server上运行的sshd,然后在vnc_server上运行的sshd将此数据包转发到localhost:5901,它本身就是端口5901 (vnc_server)。 响应数据包遵循路径的相反方向。 因此,可以将localhost的端口1111视为vnc_server上的端口5901。

2)在vnc_server上创建一个vncserver (2) Create a vncserver on vnc_server)

If you haven’t set the vnc password, use “vncpasswd” to set it first. Then set up a vncserver:

如果尚未设置vnc密码,请先使用“ vncpasswd”进行设置。 然后设置一个vncserver:

vncserver

If it successes, it will give a message like this:
New ‘vnc_server:1 (username)’ desktop is vnc_server:1

如果成功,它将给出如下消息:
新的“ vnc_server:1(用户名)”桌面为vnc_server:1

1 means this is the first desktop. The port for this desktop is 5901. the nth desktop’s port is 590n.

1表示这是第一个桌面。 该桌面的端口为5901。第n个桌面的端口为590n。

3)现在连接到客户端上的vnc服务器 (3) Connect to the vnc server on client now)

On the client side:

在客户端:

vncviewer localhost:1111

Now enjoy it ;)

现在享受它;)

After finished using this desktop, remember to close is on the server side:

使用完此桌面后,请记住要在服务器端关闭:

vncserver -kill :1

1 is the server number that is used.

1是使用的服务器号。

翻译自: https://www.systutorials.com/how-to-remote-control-linux-server-using-vnc-through-ssh-tunnel/

通过ssh远程重启vnc

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值