If you are interested in learning cybersecurity you may have heard of TryHackMe, you will know that in order to interact with the laboratory they provide you need to either use an operating system from the browser (which they provide you with) or use your own operating system and connect to the VPN of this company, this from the personal . ovpn file that the platform gives you. This practice is not really TryHackMe’s own, since connecting through a VPN to an internal network is done in most companies, so it is not something you can pass up for convenience, you must learn how to do it and, luckily for you, it is very easy to do.
On the other hand, you should know that almost all the platforms that give you the opportunity to use a VPN connection usually explain how to do it. If you have arrived here, we will assume that either you did not read any of their documentation or you did not understand it, either way, you are already here and we are going to help you.
How to download the configuration file
Located here, you are going to download the configuration file, choosing the VPN server you want, when you have the downloaded file, you must locate its path in the system, in our case, it was downloaded in the download directory, so we are going to move it to a new directory to have all the information more organized. Note that the file will be downloaded and it will be called (your-username).ovpn in our case we renamed it to “thm.ovpn”.
VPN connection to TryHackMe
Once you have the downloaded file, you must use it to connect via VPN, as this file has ovpn extension, it means that we must run it with the OpenVPN tool, hence the extension, ovpn, OpenVPN. To achieve this execution, it is as simple as running the tool, followed by the path of the file with ovpn extension, as follows.
sudo openvpn (path-to-file-ovpn)
After executing the command, you will get the following output on the screen, which will show you the connection process and finally tell you that you are now connected to the TryHackMe network.
And if we check with the “ifconfig” command, to see all the active network interfaces on the system, we will see that in addition to the interfaces that were already there, one has been added, corresponding to this VPN connection, and where we can see the IP address that has been assigned to us for this network (there is absolutely nothing wrong because you can see it, calm down).
As you can see, it is very simple to make the VPN connection, but this way is not the most optimal, because you will have to leave a window of the emulator always open to keep the connection active, as I said, this is not the most efficient, for your luck we are going to give you a command to run whenever you connect via VPN either to TryHackMe, HackTheBox, etc, this command is part of the first with some slight additions and it is as follows.
su root -c "openvpn (ruta-al-fichero-ovpn) 1>/dev/null &"
The first thing you will notice is that we no longer use the command “sudo” but we use “su root -c” to execute the command as the root user, this is because if we execute the command “sudo” a priori, it will show us on the screen an input to collect the password that we provide, but since the command also includes “1>/dev/null” which is to redirect the standard output (stdout) which is represented on Unix systems with the number 1, to the /dev/null directory, then nothing will be displayed and we will not be able to execute the command, as such. There are ways to use “sudo” with this command, but it is simpler if we directly execute the command as root.
Now, continuing with the modifications, you will see that the stdout goes to /dev/null, as such this redirection is so that this output is not displayed on the screen since going to /dev/null is like going to tell the one you like your feeling, that is, a trip with no return, and finally, with an “&”, this is so that the process created by the command goes to the background.
When executing this command you will see that, it asks for the password of the root user, this output is displayed because the command to redirect all the stdout is inside the command to execute, inside the quotes, so, it only affects this one.
When you do this, you have the VPN connection and can continue to use the same terminal emulator window as normal.
How to disconnect from TryHackMe VPN
If you connected to the VPN, either by the traditional method or by the one we show you, you can disconnect from it by eliminating the process that keeps it active. If you connected in the first way, by pressing Ctrl + C you will stop the process and the VPN connection will be inactive.
Now, if you did it the second way, you will not be able to do a Ctrl + C since the process is not active in your current terminal, so, you must kill the process either by starting from its PID or what is simpler, kill all openvpn processes.
sudo killall openvpn
With this command you are going to kill all the OpenVPN processes, be careful with this, you will kill all the connections you have with OpenVPN, not only the TryHackMe one, although if you are only using the TryHackMe VPN, there will only be one process, which will be the one that will go with San Pedro.
And with this, you now know how to connect to the VPN of this cybersecurity platform and how to disconnect, which is important because many users disconnect directly by shutting down or restarting the system, which is not necessary to be able to terminate the connection with a VPN, and this process also applies to HackTheBox’s VPN, now it is also interesting for you to read a comparison between TryHackMe and HackTheBox to complement your knowledge and know which platform to use depending on your cybersecurity level.