Dot Bash History
User Generation Script and Load Monitoring

Dot Bash History

I have prepared a GitHub repository where you can find many useful commands and scripts. The following explains how you can use one of the scripts to have a zero cost VPN of your own.

With the Amazon AWS EC2 plan, you can have a Linux server with one CPU core and little RAM for one year free of charge. Although the basic plane is not enough for any computational task, for just redirecting packets and acting as a private networking server, it is plenty.

In this article, I will walk you through setting up a server and running the script for generating user profiles. Later you can copy/paste these profiles to a mobile application and share them with family and friends.

First, we need to set up our server. For that, we should provide Amazon with details of a credit or debit card. Unfortunately, that may not be an option for my dear friends in Iran.

After registering with AWS you will have access to your Console.

No alt text provided for this image

Choose EC2 and then Launch an Instance option. After that choose Ubuntu and leave the rest unchanged. After you hit Launch Instance it will take a few minutes to be ready. If it is the first time you do that, it will also create a key for you to log in to the server. That key will be automatically downloaded upon server creation. Check your download folder. When the instance was ready, copy the IP address and use the following command in the command line to login to the server:

ssh -p 22 -i "mainkey.pem" ubuntu@<your IP address>        

Make sure the address to the key is correct.

After the previous command you should be in the server:

No alt text provided for this image

On the server, we will create a script that changes the SSH setting to allow us to use SSH tunneling. This script also creates 50 users with random passwords and stores those profiles in a format that is recognizable by NetMod Syna Android application.

There is one complication though. Because port 22 is the default port for SSH, after a while the private network may stop working in Iran. What we should do is change the default port to something random looking. But we are already using SSH and we are connected to our server. The moment that we restart SSH service on the server with the new setting, we may lose our connection.

What we do is as follows:

  1. We run the script, change SSH settings, generate user profiles, and copy/paste them onto our local PC.
  2. We restart the SSH service. At this point, we may lose the connection on the terminal.
  3. On AWS Console we add a new Inbound Rule to the Security Group related to our instance which allows traffic on the new random-looking port.

The following is the script that does most of the work:

#!/bin/bas

PORT=17456

if [ ! -f /etc/ssh/sshd_config_bak ]; then
        cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak
fi

sed -i 's/#Port 22/Port '"$PORT"'/' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
sed -i 's/#PermitTunnel no/PermitTunnel yes/' /etc/ssh/sshd_config

if [ -f ./users.txt ]; then
        rm ./users.txt
fi

MYIP=$(curl -s https://checkip.amazonaws.com)

for i in {1..50}; do
        PASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 20 | head -n 1)
        deluser "user$i" &> /dev/null
        useradd "user$i" --shell /sbin/nologin
        echo "user$i:$PASS" | chpasswd
        echo "ssh://user$i:$PASS@$MYIP:$PORT#Profile $i" >> users.txt
done
cat users.txth        

You can create this file using nano:

sudo s
nano setupvpn
# copy paste the script
# use `ctrl+x` then `y` then `enter` to save the script.
chmod +rwx setupvpn
./setupvpn
# copy paste output
systemctl restart sshu        
No alt text provided for this image

After finding the Inbound rules on the AWS management console, add a field like the following:

No alt text provided for this image

You can copy all 50 profiles into NetMod Syna and later share a locked version of each profile with your family members and friends.

The whole process can be done in under 10 minutes and based on the feedback that I have received the connection is reliable and fast.

Hopefully you have found it helpful. If you have a command in mind please share.

To view or add a comment, sign in

More articles by Mohammad Rahimi

  • Programming Policies

    Picture this situation: you've got a continuous flow of data coming in, and your task is to process it and present the…

  • Exception x Exception

    In my previous post, we demystified std::forward. In this one, we'll explore what happens when you encounter another…

  • Forward Demystified

    In this post I have shed some light on one of the darker corners of the C++ language: std::forward. The code snippets…

  • Maintainer's Dream

    The distributed workflow for Linux source code development is called Benevolent Dictator. Some maintainers collect…

    2 Comments
  • FTowerX

    A few years ago, I was developing a program for remotely controlling a signal generator. I wanted to create a simple…

    1 Comment
  • GitCheat

    In my previous post, I introduced a long-existing tool that helps you migrate your workflow from Perforce to Git. Here,…

  • Perforce meets Git

    Perforce is a Centralised Version Control System founded in 1995 and used by many companies. Git came into existence…

  • In Mail IP

    I was planning to run a home server and access it remotely. But there was an issue.

    2 Comments
  • StateBench

    While developing software, from large to small scale, you can use state machines to reduce code complexity and help…

  • C++ and Benchmarking

    It may sound extreme, but I believe benchmarking too should get the special treatment of testing in a project. There…

Others also viewed

Explore content categories