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.
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:
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.
Recommended by LinkedIn
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:
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
After finding the Inbound rules on the AWS management console, add a field like the following:
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.