(Note: It's recommended to read the article on How The Internet Works before reading this article. It'll really help increase your understanding.) To watch the youtube video where I explain this topic, please click here. What Is a VPN?
Well, that's why VPNs come in handy. VPNs encrypt your data, send it to a VPN server (which is just a special computer on a trusted network) which then unencrypts the data and proceeds to do exactly what we were going to do with it before, as seen in the picture below. (Follow the colors to see what's happening! Start from the bottom left.) A VPN works by encrypting your data right on your device, and sending that data to the VPN Server. That VPN server unencrypts the data, and sends it to the website's server like you normally would. The difference is, the hacker on your local network only sees encrypted (inaccessible) data now. (Hopefully, the VPN network is safe and has no hackers on it.) Of course, the whole purpose of a VPN is predicated on the VPN's network being secure. (If there's a hacker on the VPN's network, then there's no point in using a VPN at all.) The theory behind the VPN also comes with some additional benefits. Let's look at the reasons to use a VPN. Why/When To Use a VPNThere are three main reasons to use a VPN: 1. Security - If you're away from home and on someone else's wifi, then the websites you visit and anything you do (ex. login, post information) can be intercepted by a hacker or by the network owner. If you use a VPN, then all the information on your device is encrypted, meaning that anyone who intercepts the data won't be able to do anything useful with it. 2. To be on a certain network - VPNs basically make it so that your device is "on" the VPN server's network. There are three reasons this could matter:
3. To hide your activity - Using a VPN hides the activity from the wifi/network that you're on. This not only hides it from the network owner or hackers, but also hides the activity from the network ISP. This is useful in cases where people want to use VPN's to download copyrighted content without getting in trouble with their ISP (ex. torrenting). (I don't recommend this, by the way.) Those are the main reasons for using a VPN. . We'll be focusing on reasons (1) and (2) as the motivation behind creating our own VPN. How Can We Make Our Own VPN Server?Let me preface this by saying: I don't know of any paid VPN solutions. ("Paid solution" meaning that you pay to connect to someone else's VPN server.) I'm not going to recommend any, and I personally wouldn't use them since I don't know whose computers I'm connecting too. (That defeats the entire purpose of being secure, lol...) Personally, I like to set up an old laptop up, a cheap Raspberry Pi, or even my main desktop up as a VPN server so that when I'm away from home, I can still be on my home network. However, it is possible to create your own VPN server on a cloud hosting service, such as AWS or Digital Ocean. (If you trust their networks.) There are two things we need to do to make a VPN server:
There's a simple way to do this for Windows, and a Super Hard (but proer) way to do this for Linux. Don't be scared, I'll walk through everything necessary. The Simple Way (Windows 10 Built-In PPTP)This is a topic in itself, and so I've moved this section to be a separate blog post. Click here to set up your own VPN server on Windows 10. The Super Hard, Super Hacker Way (Linux + OpenVPN)To be honest, the method of creating your own VPN Server using Linux isn't for the faint of heart. However, I've made it as simple as possible by giving only the necessary commands. Want to make your own Linux VPN Server? Then go to this blog post. {Link to be added later.} ConclusionWe looked over what a VPN is and how it works, as well as the benefits that come with using them. If you feel that there's some aspect of using a VPN that you'd like to have available to you, then you can create your own. I personally find it great to set them up at your own house (or at a relative's house), but if you want to set it up on a cloud service like Digital Ocean, then try to find a service you trust. To watch the video of me explaining this topic, please watch the following video: Like this content and want more? Feel free to look around and find another blog post that interests you. You can also contact me through one of the various social media channels.
Twitter: @srcmake Discord: srcmake#3644 Youtube: srcmake Twitch: www.twitch.tv/srcmake Github: srcmake
If you'd prefer to watch the youtube video explaining and going over these commands, please click here.
What Is Docker?
Have you ever tried to use someone else's code/project, only to find that something fails because you don't have a particular library set up on your environment?
Docker is a lightweight container that lets someone set up an environment that's suited for their project with all the dependencies required. Then, anyone who uses that container has the environment set up so that they don't have to do anything else. In more concrete terms, we basically create a tiny virtual machine with low resources, it runs an operating system, we can install the required project dependencies/libraries, and whoever uses our project runs the code on top of that docker container. Installing Docker
Let's install the latest edition of Docker on our computer. For the purposes of this tutorial, we're going to be assuming that we're going to be using Ubuntu linux; if you're using a different version of Linux or Mac, then change commands 2 and 3 to the appropriate urls. You can find the appropriate download link here. (Shout out to Digital Ocean for having an awesome article teaching about these commands.)
Run all of the following commands in the terminal.
sudo apt-get install curl
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
apt-cache policy docker-ce
sudo apt-get install -y docker-ce
We install curl, and get the latest version of docker available for Ubuntu (the OS we're using). We update the package, make sure that the version we downloaded is the one we're using (as opposed to the version that comes by default with our Ubuntu), and finally we install it. To make sure the installation was correct, let's run a simple Hello World docker command.
sudo docker run hello-world
You'll know if it works or not. And with that, we've installed docker on our computer! Using Docker
Okay so we have docker on our computer. How do we actually use it?
Well, the way docker works is we create our own image of our machine state. Basically, we need to pick an OS, and then we can install some dependencies on it to set it up the way we'd like. (And then, we can create or get a project onto the machine.) Let's start by finding an image. In the terminal, type:
sudo docker search ubuntu
This searches for all ubuntu docker images available online. The result will be something like: The image named "ubuntu" has a lot of stars, so let's download that one. Let's download that image:
sudo docker pull ubuntu
Now we have that ubuntu image downloaded onto our computer. Let's look at all the images we have available locally, by typing the following command:
sudo docker images
This will show the images that we have on our computer. We can see that we have the hello-world image from before, and the ubuntu image that we just pulled. Let's run the ubuntu image. Use the following command.
sudo docker run -it ubuntu
This will take us into the terminal for the ubuntu image. We're basically in a virtual machine now! Now you have a docker image that's running ubuntu, but you can install any dependencies you need too (node, python, etc.) and if you want, you can even create/pull any project that you want to run on that virtual machine. Take a note of the container id while you're in the image.
(Pro-tip: No need to use sudo inside the docker image terminal, since you're already the root user.)
As you can see in the image above, to leave the docker image and go back to your own terminal, just type exit inside of the image terminal:
exit
Okay, so we were inside of our image and set it up the way we like. Why don't we save the state of this docker container as a separate image. Use the following command:
sudo docker commit -m "nothing" -a "srcmake" 4b1c0c8872cc nodejsubuntu
We commit our image, specifying the commit message "nothing" (which isn't descriptive...), saying that the author is "srcmake", giving the container id (see above for getting this), and the specific name of the new image we're creating. If we run the "docker images" command once again, we can see our newly created image on our list of local images. To view the number of containers that we have running, use this command:
sudo docker ps -a
It'll show our containers, as seen in the following pictures. To stop a container from running, use this command:
sudo docker stop {containerid}
And with that, we know how to use Docker! How To Save and Share Your Docker Image
Okay, so we can make a super cool container that runs our project. How do we give this docker image to other people so that they can use it?
First, we'll save our docker image to a file. Use the following command:
sudo docker image save -o myimage dcbe1d3b9b6e
We save the image whose id is dcbe1d3b9b6e to a file named "myimage".
There isn't some fancy "it worked!" message, but the file shows up in our directory meaning it's a success. And that's it! Give that image file to whoever you want too, and they have your docker image. They can load your docker image using the following command:
sudo docker image load -i myimage
You'll see a tiny message for the loaded image. And with two simple commands, we can share images. When To Use Docker
When should we use Docker? Basically, any time that a project's dependencies are a little special. In a professional setting, it's good to have an entire project not just be about the code, but also having the dependencies accounted for by having a docker to run the code.
To watch the youtube video that goes over these commands, please click the video embedded below:
Like this content and want more? Feel free to look around and find another blog post that interests you. You can also contact me through one of the various social media channels.
Twitter: @srcmake Discord: srcmake#3644 Youtube: srcmake Twitch: www.twitch.tv/srcmake Github: srcmake
If you'd prefer to view the youtube video for this topic, please click here.
What Is a Python Virtual Environment?
So you create a super awesome python program and want to share it with someone. But it turns out that your code requires libraries that are on your computer, but not on other people's computers. That means they would have to install the libraries on their computers, but this creates confusion about which libraries are necessary, how they install it, which version of they need, etc.
The solution to this is to create a Python Virtual Environment. This is similar to NPM for Node: if there's a python library that your project requires, you can install that library locally (in the project folder) instead of just doing a global pip install on your computer. How To Create a Python Virtual Environment
So how do we use a python virtual environment? First let's make sure that we have python and pip installed on our computer. (The following commands will [probably] work for linux and Mac.) In a terminal, type:
sudo apt-get install python sudo apt-get install python-pip Next, let's make sure we actually have the virtual environment library/command available to us. Use pip to install it: sudo pip install pipenv Good? Good. Now we have all the tools we need to make a python project and set up the files in our virtual environment. Let's pretend that our project consists of a single python file called main.py with the following code:
Two simple lines of code. Now let's try to run the python file. In the terminal: python main.py Does it work for you? It might, depending on whether or not you have the scapy python library installed on your computer. If you don't, then you'll get an import error. Normally, we'd install the library onto our computer globally using "pip install scapy", but instead, let's install into the local project by using a python virtual envionment. Type the following command into your terminal: pipenv install scapy That will tell your python virtual environment command that this project requires scapy. What happens if we try to run the project now? python main.py Actually, the same import error will occur. You installed the library through pipenv, so now you need to run the python file(s) through pipenv so that pipenv can include the required libraries. pipenv run python main.py Now we can see the Hello World in the terminal. This is because pipenv included the scapy library so that the import line didn't give an error. When To Use a Python Virtual Environment
So when should we use this? Honestly, for every project that we intend to share with anyone, we should include a python virtual environment. That way anyone who receives the project won't have library compatibility issues.
If you'd like to watch the youtube video that walks you through going through these commands, please watch the video embedded below:
Like this content and want more? Feel free to look around and find another blog post that interests you. You can also contact me through one of the various social media channels.
Twitter: @srcmake Discord: srcmake#3644 Youtube: srcmake Twitch: www.twitch.tv/srcmake Github: srcmake |
AuthorHi, I'm srcmake. I play video games and develop software. Pro-tip: Click the "DIRECTORY" button in the menu to find a list of blog posts.
License: All code and instructions are provided under the MIT License.
|