Setup SSL Tunnel Using Stunnel on Ubuntu

The Stunnel program is designed to work as an SSL encryption wrapper between remote client and server. It can be used to add SSL functionality.

What Stunnel basically does is that it turns any insecure TCP port into a secure encrypted port using OpenSSL package for cryptography.

1.Update & Upgrade Ubuntu

apt-get update && apt-get upgrade

2.Install Stunnel on VPS

apt-get install stunnel4 -y

3.Create SSL Certificate

openssl genrsa -out key.pem 2048
openssl req -new -x509 -key key.pem -out cert.pem -days 1095
cat key.pem cert.pem >> /etc/stunnel/stunnel.pem

4.configure Stunnel on VPS

vim /etc/stunnel/stunnel.conf

So overall the “stunnel.conf” file must contain the lines below:

client = no
[squid]
accept = 8888
connect = 127.0.0.1:3128
cert = /etc/stunnel/stunnel.pem

Note: The client = no part isn’t necessary, Stunnel by default is set to server mode.

Also, enable Stunnel automatic startup by configuring the “/etc/default/stunnel4” file

ENABLED=1

Finally, restart Stunnel for configuration to take effect, using this command:

/etc/init.d/stunnel4 restart

5.Install Squid Proxy

apt-get install squid3 -y

Configure Stunnel in Client

Using a SFTP client such as Filezilla, connect to your server and download the “stunnel.pem” file located in “/etc/stunnel/” directory to the client.

Install Stunnel on your choice of OS. Then go to the Stunnel folder and move the downloaded certificate “stunnel.pem” to Stunnel folder.

So “stunnel.conf” file in the client should look like this:

cert = stunnel.pem
client = yes
[squid]
accept = 127.0.0.1:8080
connect = [Server’s Public IP]:8888

Save and close the file and run “stunnel.exe”.

That’s it. Now when we want to connect to Squid proxy on our cloud server, we must configure our client to connect to 127.0.0.1:8080, and Stunnel automatically connects us through a secure tunnel to the service specified for that port.

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
What is OS Watcher Utility and How to use it for Database Troubleshooting ?
Viewed 32574 times since Thu, Jun 21, 2018
Turbocharge PuTTY with 12 Powerful Add-Ons – Software for Geeks #3
Viewed 16168 times since Sun, Sep 30, 2018
RHEL: Services basic management - chkconfig
Viewed 7201 times since Sat, Jun 2, 2018
How to Register and Enable Red Hat Subscription, Repositories and Updates for RHEL 7.0 Server
Viewed 16893 times since Mon, Oct 29, 2018
ZPOOL: Add a mirror to a concat zpool
Viewed 4869 times since Sun, Jun 3, 2018
Modifying the inode count for an ext2/ext3/ext4 file system
Viewed 18455 times since Fri, Sep 18, 2020
10 Linux DIG Command Examples for DNS Lookup
Viewed 12203 times since Sun, Sep 30, 2018
RHCS6: ’fencing’ basics
Viewed 3329 times since Sun, Jun 3, 2018
LVM: Reduce an existing Logical Volume / Filesystem
Viewed 4482 times since Sat, Jun 2, 2018
Super Grub2 Disk
Viewed 7756 times since Wed, May 22, 2019