Setup x11vnc server on Linux with android vnc clients

Posted on 20 views

Welcome to this exciting article where we get to install x11vnc server on CentOS / Rocky and Manjaro. After that, we shall use two android vnc clients (VNC Viewer and androidVNC) to connect to the servers.

“Mountaintops are for views and inspiration, but the fruit is grown in the valleys.”
-Billy Graham

Introduction

The notion of controlling your computer via your Android device is absolutely amazing. The set up can be a huge convenience for you especially if you would not like to carry your computer around while monitoring critical processes running in it. The good news is that it is possible to control your laptop or any network-enabled computer through your pocket smartphone friend. After trying out many packages and applications, the following set up worked for me in my CentOS / Rocky and Manjaro Linux boxes. The set up here is that the phone and the machines are on the same subnet.

Install on Ubuntu / Debian

Run the commands below to install VNC Server on Ubuntu / Debian systems

sudo apt update
sudo apt install x11vnc

1. Install x11vnc server on the CentOS / Rocky Linux

The first step was the installation of x11vnc server on the CentOS / Rocky box. The easiest way to accomplish this is by going to software applications app and searching for x11vnc. Click on the installbutton once you find it. Alternatively use yum command:

$ sudo yum install x11vnc
Dependencies resolved.
======================================================================================================================================================================================================
 Package                                                  Architecture                             Version                                          Repository                                   Size
======================================================================================================================================================================================================
Installing:
 x11vnc                                                   x86_64                                   0.9.16-3.el8                                     epel                                        927 k
Installing dependencies:
 avahi-libs                                               x86_64                                   0.7-20.el8                                       baseos                                       61 k
 libICE                                                   x86_64                                   1.0.9-15.el8                                     appstream                                    72 k
 libSM                                                    x86_64                                   1.2.3-1.el8                                      appstream                                    46 k
 libXcursor                                               x86_64                                   1.1.15-3.el8                                     appstream                                    35 k
 libXdamage                                               x86_64                                   1.1.4-14.el8                                     appstream                                    26 k
 libXdmcp                                                 x86_64                                   1.1.3-1.el8                                      appstream                                    40 k
 libXfont2                                                x86_64                                   2.0.3-2.el8                                      appstream                                   147 k
 libXi                                                    x86_64                                   1.7.10-1.el8                                     appstream                                    48 k
 libXinerama                                              x86_64                                   1.1.4-1.el8                                      appstream                                    14 k
 libXmu                                                   x86_64                                   1.1.3-1.el8                                      appstream                                    74 k
 libXrandr                                                x86_64                                   1.5.2-1.el8                                      appstream                                    33 k
 libXt                                                    x86_64                                   1.1.5-12.el8                                     appstream                                   184 k
 libXtst                                                  x86_64                                   1.2.3-7.el8                                      appstream                                    21 k
 libfontenc                                               x86_64                                   1.1.3-8.el8                                      appstream                                    36 k
 libvncserver                                             x86_64                                   0.9.11-17.el8                                    appstream                                   274 k
 libxkbfile                                               x86_64                                   1.1.0-1.el8                                      appstream                                    87 k
 lzo-minilzo                                              x86_64                                   2.08-14.el8                                      baseos                                       27 k
 tcl                                                      x86_64                                   1:8.6.8-2.el8                                    baseos                                      1.1 M
 tk                                                       x86_64                                   1:8.6.8-1.el8                                    appstream                                   1.6 M
 xorg-x11-server-Xvfb                                     x86_64                                   1.20.11-2.el8                                    appstream                                   870 k
 xorg-x11-server-common                                   x86_64                                   1.20.11-2.el8                                    appstream                                    41 k
 xorg-x11-xauth                                           x86_64                                   1:1.0.9-12.el8                                   appstream                                    38 k
 xorg-x11-xkb-utils                                       x86_64                                   7.7-28.el8                                       appstream                                   113 k

Transaction Summary
======================================================================================================================================================================================================
Install  24 Packages

Total download size: 5.8 M
Installed size: 16 M
Is this ok [y/N]: y

After it has successfully installed, look for the application and launch it. A GUI prompt will be presented to you titled Select x11vnc port. On this prompt, choose the port you would wish the server to be running on. I will be using.port 5901 After this choose Listen on Localhost (this is a good security measure instead of exposing it to your LAN) and click OK. A new prompt will be called after a short while with new options to set.

Check the relevant options that will suit your needs here. Enter a password and verify it. Click Apply and OK after you are done. At this point, your x11vnc server is running.

The second step is all about your phone, I hope you are ready to get this feature for your enjoyment.

Screenshot_20180426-233545
Screenshot_20180426-233640
Screenshot_20180426-234106
Screenshot_20180426-234125
Screenshot_20180426-234203

Launch play store and search for ConnectBot and install it when you get your hands on it. This is an application that is going to help us tunnel our vnc requests via ssh by forwarding our ports running in the Centos7 server locally.

After you have successfully installed the app the next step is keying in the IP address and the rest of the essential credentials.

Make sure you ssh into your computer at this point and check out if it works.

When connected, click on the menu and create the forward as follows:
Touch Port Forwards on the screen.

Touch + button or Add port forward menu depending on your phone type
Key in the following data on the blank spaces.
Nickname: tech
Type: Local
Source Port: 5901
Destination: localhost:5900

A very important step is the ports you enter. Make the source port the port you chose on the GUI [5901 in this case and the destination as any port like 5900].

The source port is the port the server opens and allows us to access the screen of the computer. After entering the ports, please disconnect ssh and reconnect again with the updated port data.

Screenshot_20180427-024554
Screenshot_20180427-024605

We know the process might have been long but one more step is all we have before we can control our computers via our android phones.

Let us go:

Once again, launch play store and look for androidVNC.

Install, launch and key in the following data on the spaces it will present.
Password: (Rememeber password we set up on the x11vnc gui prompt? Enter it here and check the Keep box so that you don’t keep keying it in every time)
Address: 127.0.0.1 (or localhost)
Port: 5901 (This should be the source port you keyed into ConnectBot, do not forget about this or else you won’t be able to get connected)

Leave the rest of settings blank or default then touch on the Connect button and there your current computer screen will appear on your android phone. Well done guys. This is the point where you can grab a cup of Java.

2. Manjaro / Arch Linux / Garuda / EndeavourOS

a. Installation of x11vnc.
The package is available in the repositories, therefore invoke the following on your terminal

sudo pacman -S x11vnc

b. Set Password
Use the commands below to set password.

$ x11vnc -storepasswd

You will be prompted to enter a password and verify it. Please enter a suitable password here. The password will be saved in /home/user_name/.vnc/passwd

Another way is by invoking the following commands where password is your chosen password. The password will be stored in the ~/.x11vnc/passwd file.

$ mkdir ~/.x11vnc
$ x11vnc -storepasswd password ~/.x11vnc/passwd

c. Create A Log File
You can create a log file manually in /home/user_name/.vnc/x11vnc.log

d. This is a command that you can invoke to start the x11vnc server (please make sure you use the user name you set in the “user_name” part)

$ x11vnc -nap -wait 50 -noxdamage -rfbauth $HOME/.vnc/passwd -display :0 -nocursor -forever -o $HOME/.vnc/x11vnc.log -bg

The above command will return a result that looks like:

PORT=5903 or PORT=5900

Also, note that you can change to-display :0 another value like -display :1 if you like. The port you will forward will be output on the screen e.g PORT=5903 as mentioned. This is the port that will be designated to the source port in ConnectBot android app.

Launch play store and search for ConnectBot and install it when you get your hands on it. This is an application that is going to help us tunnel our vnc requests via ssh by forward our ports running in Manjaro locally.

Screenshot_20180426-234125 (1)
Screenshot_20180426-234203 (1)

After you have successfully installed the app the next step is keying in the IP address and the rest of the credentials. ssh into your computer at this point and check out if it works just like before. When connected, click on menu and create the forward as follows:

Touch Port Forwards on the screen.

Touch Add port forward menu depending on your phone type

Key in the following data on the blank spaces.

Nickname: tech
Type: Local
Source Port: [In case the last command you invoked on the terminal returned PORT=5901, assign 5901 here. The destination value you will key in the ConnectBot android application becomes 5902.

Destination: localhost:5902. After you set up the port forwards, make sure that you disconnect all connections and reconnect again so that we use the updated forwarded ports on the vnc android client.

The next step is setting up your android vnc client. For this setup, we are going to use Android VNC Viewer for various purposes. Let us roll our sleeves and go:

Screenshot_20180427-001800
Screenshot_20180427-001854
Screenshot_20180427-001921

Launch play store and look for.VNC Viewer

Install, launch and key in the following data on the spaces it will present.

On the address field enter 127.0.0.1:5901 (note that we have used the source port and not the destination port). Refer to the source port you entered in your running ConnectBot and use the port to bind the local loopback address shown as 127.0.0.1:5901. I emphasize this because it is very important for the connection to succeed.

Enter any name for the Name value then click save and connect thereafter.

You will be asked for the password you entered when prompted after invoking the # x11vnc -storepasswd command

Conclusion

Thank you for visiting and following through the article. I hope controlling your desktop or any other computer via your android phone will be much fun. Keep the spirit of learning high.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.