Setting up a reverse tunnel to a local machine




What are we going to do?

  • Setup a secure virtual host in Apache Server using reverse proxy
  • Create a SLL/TLS certificate using Let’s Encrypt
  • Setup a reverse SSH tunnel on the client


This post expects the following prerequisites:


  • A server that is accessible from internet
  • Apache Server up and running



DNS and domain

  • A domain or subdomain that points to the server

Setup a secure virtual host in Apache Server using reverse proxy


Create a virtual host

Create a virtual host file.

$ sudo nano /etc/apache2/sites-available/

And add the following contents to it.

<VirtualHost *:80>
    ProxyPass /
    ProxyPassReverse /
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined






Add a SSL/TLS certificate


Install Let’s Encrypt Certbot with the following commands.

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-apache

Now generate and install the certificate.

$ sudo certbot --apache -d


Test the virtual host

Now we need to enable the Apache virtual host.

$ sudo a2ensite

Check if the configuration is valid.

$ sudo apache2ctl configtest


$ sudo systemctl reload apache2


Setup a reverse SSH tunnel on the client



ssh -vR 8888:localhost:8080 -l nidkil

The options mean the following:

  • -v: Verbose output.

Force SSH to use a specific private key


Lets create the config file.

$ notepad ~/.ssh/config

Add the following contents to the config file.

    IdentityFile ~/.ssh/your-private.ssh.key







How cool is that?

Setup certificates for automatic renewal


$ sudo crontab -e

Add the following line to the Crontab file.

0 2 * * 0 certbot renew && systemctl restart apache2





Debug SSH Server


$ sudo tail -f /var/log/auth.log



Open the SSH config file.

$ sudo nano /etc/ssh/sshd_config

Look for the following line.

LogLevel INFO

And change it to: VERBOSE.


And restart the SSH Server to activate the change.

$ sudo service ssh restart

Debug SSH client




Change root password Windows Subsystem for Linux

Today I was setting up Windows Subsystem for Linux and wanted to change to the root user using the command:

su -

I was prompted for the password, but had no idea what it was. So I needed to figure out another way of switching to the root user instead of prefixing every command with sudo. Did I say switch and prefix and sudo? O yes, stupid me.

sudo su

Don’t forget to exit once you are done. And be careful not to wrech havoc while working under the root account. Have fun!

PT Magic setup on Ubuntu 17.10


In this post I will explain how to install, configure and run PT Magic (PTM), a free add-on for the Profit Trailer (PT) cryptocurrency trading bot, on a VPS using Ubuntu. As an extra security precaution the PTM GUI is only accessible through a SSH tunnel using PuTTY with port forwarding. This avoids opening additional ports on the VPS to the outside world.

Continue reading

Setting up Mutt to send mail using Gmail with 2FA set


I needed to be able to send mail from the command line on one of my servers. A quick way to do this without setting up a mail server is using Mutt to send mail using Gmail. In this post I will give a short write-up how to install and configure Mutt on Ubuntu. As I have two factory authentication setup on Google an app specific password is required instead of the regular Google account password.

Continue reading