Skip to content

Instantly share code, notes, and snippets.

@BrittonWinterrose
Last active March 26, 2019 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrittonWinterrose/87d7477da97a414b0b2f92178b281a74 to your computer and use it in GitHub Desktop.
Save BrittonWinterrose/87d7477da97a414b0b2f92178b281a74 to your computer and use it in GitHub Desktop.
Create a tinyproxy with Basic Authentication on Ubuntu

Tinyproxy Compile and Install - Configure tinyproxy as follows

You will need to be SSH'ed into the computer for this.

1. Make sure you're root. If not, run:

sudo su

2. Update your system:

apt update && apt upgrade -y

3. If you have less than 1GB of RAM, you can create a swap file which will be used as RAM if your system runs out. It's the Linux equivalent of the Windows pagefile. This is optional but generally good for performance. Check your ram by running this:

free -g

First make sure your VPS does not already have a swap file or partition.

swapon

If this command outputs nothing, you do not have swap space. If it does, you already have swap space and should not need to create more. Skip to step 4.

Else, you do need to create a 1GB swapfile:

dd if=/dev/zero of=/swapfile bs=1k count=1M

Then, Set correct permissions:

chmod 600 /swapfile

Then, Activate it:

mkswap /swapfile
swapon /swapfile

Then, Save a line in your fstab, so when you reboot, your system will automatically use that swap space.

echo "/swapfile swap swap defaults 0 0" >> /etc/fstab

4. Install some packages:

apt install -y git make automake nano build-essential
apt-get install cmake asciidoc
  • git is for grabbing tinyproxy from github
  • nano is an easy-to-use text editor
  • build-essential is for ascii support
  • automake is for compliling and installing our code
  • asciidoc is for making the docs. Skip if you plan to skip step 7.

5. Download tinyproxy (the following command will always grab the most recent version):

git clone https://github.com/tinyproxy/tinyproxy.git

6. Then compile the make file.

cd tinyproxy/
./autogen.sh
./configure

Sometimes autoreconf -i works better than ./autogen.sh. Try if you have issues with ./autogen.sh.

7. Edit the Make file. This step is optional if you don't need documentation created.

Launch Nano

nano Makefile

Find the section that starts with SUBDIRS = \ (it should be line 343), remove the line docs \ So the section should now look like this:

SUBDIRS = \
src \
data \
etc \
m4macros \
tests \
scripts

Then press Ctrl + s then Ctrl + x to exit nano.

8. Finish the Make & Install process

make
make install

9. Edit the Configuration File:

nano /usr/local/etc/tinyproxy/tinyproxy.conf

10. And make the following changes:

  • Group nobody change to Group nogroup
  • BindSame yes change to BindSame yes (this is only needed if you have multiple public IPs)
  • #LogFile "/usr/local/var/log/tinyproxy/tinyproxy.log" change to LogFile "/var/log/tinyproxy.log" (Only if you want to save logs)
  • #Syslog On change to Syslog On (Only if you want to log via Syslog. Don't use with LogFile enabled.)
  • Allow 127.0.0.1 change to #Allow 127.0.0.1 (Using basic auth so no need to whitelist/blacklist IP addresses)
  • #BasicAuth user password > BasicAuth ChooseAUsername ChooseAPassword (Use a very strong and complex password, bots from all over the world will be constantly trying to guess it)
  • ViaProxyName "tinyproxy" > #ViaProxyName "tinyproxy" (If you don't want sites knowing you're using a proxy.)
  • #DisableViaHeader Yes > DisableViaHeader Yes (If you don't want sites knowing you're using a proxy.)

11. Press Ctrl x then y then Enter to save and exit.

Congratulations! Your proxy server is now ready!

12. Start it with:

tinyproxy

13. To make sure it is running:

ss -lntup | grep tinyproxy

If you get no output, then it is either not running, or running but not binding to a port.

14. To terminate it.

killall tinyproxy

15. Finally, add a Cron to make it run automatically after a reboot:

crontab -e

16. That will open a file in a text editor of your choice, simply add the following line at the end:

@reboot /usr/local/bin/tinyproxy

Enjoy your Proxy!

NOTES:

I like to use Syslog On because it is convenient and logs to the same place across all apt-get and Git installed packages. To see the logs when using Syslogs just enter sudo tail -n 50 -f /var/log/syslog and adjust the number value to see more or fewer lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment