Furthermore, some commands take time to run, giving you room to take a break. In such a case, someone can tamper with your work. The only way to be sure is to lock the terminal and virtual consoles. The vlock is easy to use, and we will see how you can use it to secure your system.
Installing vlock on Linux
The vlock is available on any Linux distribution package manager, and you can install it using the following command:
For Arch, Fedora, and CentOS, use the following command:
vlock Options
There are various options that vlock offers, and you can list the help page to view them. We will cover the most common ones with an example of how to use each. Let’s begin.
1. vlock Lock Current Session
Locking the current terminal session or virtual console mostly works using a shared system. However, someone can still access the other sessions and tamper with your work. Nevertheless, use the following command to lock your current session:
Once you lock the current session, anyone needing to use the session or terminal must press the enter key and enter the password to resume using it.
The following image is an example of a locked session:
2. vlock Lock All Sessions
We’ve seen how you can lock your current terminal or session. However, someone with access to the system can still open another session or terminal and interfere with your work. The solution is to lock all the virtual consoles. That way, regardless of which virtual console someone opens, they will be required to authenticate themselves.
To lock all virtual sessions, use the “–all” flag. Note that you can only lock virtual sessions, not your terminal. Otherwise, you will get an error message shown below:
To access the virtual terminals, press “ctrl + alt+ f4”. To exit, replace “f4” with “f1”.
Still, you will be required to enter the password to unlock the sessions. The good thing is that no one else can create a new virtual session. It will still be locked even if they do, keeping your sessions intact. Moreover, the other people using the system will need the root password to unlock the sessions if you are root.
3. Switching to a New Console
Before locking all your virtual sessions, you may need to switch to a new virtual session to keep working. That’s possible using the “-n” or “–new” option. The following command only works if you installed vlock with plugin support. Otherwise, you will get an error message.
4. vlock Disable SysRq Mechanism
Thanks to the SysRq key, someone can still use it and perform various operations when a system freezes. Therefore, even when you use vlock to lock your sessions, someone can still access the system unless you disable SysRq. To prevent such a situation, you need to use the “-sa” option, which only works for virtual consoles.
Conclusion
One way of keeping your Linux machine safe is by hindering anyone from tampering with your terminal sessions or virtual consoles. You can lock your current session or all your virtual consoles using vlock, and anyone trying to tamper with the system will need to be authorized. Want to protect your Linux machine? Use vlock.