How to Remote Control Linux Server Using VNC through SSH Tunnel

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.

The default window manager of vncserver is twm.

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

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:

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.

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:

vncserver

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

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

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.

Similar Posts

  • Several Vim Tips (in Chinese)

    窗口模式操作 CTRL-W CTRL-S 将当前窗口分割为两窗口 CTRL-W CTRL-W 切换窗口 CTRL-W j 切换到下一窗口 CTRL-W k 切换到上一窗口 CTRL-W CTRL-R 将窗口的位置轮换 CTRL-W CTRL-_ 将当前窗口最小化 CTRL-W CTRL-= 将所有窗口变为等大 搜索和替换 /word 搜索word 搜索之后按回车高亮显示,n 下一个 p 上一个 :%s/模式/替换成的内容/gc % 全局选项,如果没有开启则只在当前行进行替换 g 表示 全局替换,如果没有g选项则只替换每行出现的第一个单词 c 表示需要确认 Esc替换按键 ESC键在键盘的左上角,按起来很不方便,而在VIM中ESC经常用到,其实有一个同样作用的组合按键:CTRL-[,这两个按起来手基本不用做大的动作,方便多了。 块操作 使用visual可视模式 v 进入可视模式,移动光标可进行选择 CTRL-Q 或 CTRL-V 进入列式模式,可进行块操作,选定的是一个矩形块。如果使用behave mswin CTRL-V可能映射成为past Read more: How to convert between…

  • How to change the maximum uploading size for PHP with Apache on Linux?

    How to change the maximum uploading size for PHP with Apache on Linux? PHP has parameters to control the maximum uploading size. Here, we use Ubuntu 18.04 LTS default version as an example. First, open the php.ini configuration file using your favorite editor /etc/php/7.2/apache2/php.ini Then, find the following parts ; Maximum size of POST data…

  • Squeezing Space in LaTeX – SysTutorials QA

    How to squeeze space in Latex? A good tutorial about “squeezing space in LaTex” in here from the Cambridge University’s website: http://www.eng.cam.ac.uk/help/tpl/textprocessing/squeeze.html These settings work great for me: setlength{textfloatsep}{1pt} setlength{abovecaptionskip}{1pt} setlength{belowcaptionskip}{1pt} A more aggressive configuration to squeeze space in a LaTex doc: % save space usepackage{enumitem} setlist{nolistsep} % no space between refs usepackage{bibspacing} setlength{bibspacing}{baselineskip} usepackage[small,compact]{titlesec}…

  • Hadoop 2 (YARN) default configuration values

    Where to check the default Hadoop 2 (YARN) configuration values for: HDFS: hdfs-site.xml YARN: yarn-site.xml MapReduce: mapred-site.xml Default Hadoop 2 (YARN) configuration values for Hadoop 2.2.0 from Apache Hadoop website: HDFS: http://hadoop.apache.org/docs/r2.2.0/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml YARN: https://hadoop.apache.org/docs/r2.2.0/hadoop-yarn/hadoop-yarn-common/yarn-default.xml MapReduce: https://hadoop.apache.org/docs/r2.2.0/hadoop-mapreduce-client/hadoop-mapreduce-client-core/mapred-default.xml Read more: Good introductions to Hadoop 2.0 (YARN)? Hadoop Installation Tutorial (Hadoop 2.x) Hadoop Installation Tutorial (Hadoop 1.x) Hadoop…

  • How to get file size in Python?

    How to get a file’s size in Python from the full path of a file? You can use this piece of Python code: os.path.getsize(file_path) It returns the size in bytes. It raises os.error if the file does not exist or is inaccessible. Manual of os.path.getsize(): https://docs.python.org/2/library/os.path.html#os.path.getsize Read more: How to get a FILE pointer from…

2 Comments

  1. Actually, I think you should tell the reader how to install vncserver as
    follows ;-)

    # yum install tigervnc-server

Leave a Reply

Your email address will not be published. Required fields are marked *