In this tutorial, you will learn how to block one or more console sessions in Linux using the Vlock tool.
What is Vlock?
Vlock (Virtual Lock) is a utility that gives us the possibility to block one or several active sessions in our Linux environment allowing our session to be blocked so that other users can enter or continue working in their virtual sessions.
Install Vlock on Linux
For this, we will use the CentOS 7 distribution.
For RHEL, CentOS or Fedora, we will use the following command for the installation of Vlock:
sudo yum install vlock
For Ubuntu or Debian we will use the following command:
sudo apt-get install vlock
How to use Vlock in Linux
Once we have installed Vlock or verified that we already have it installed we can use the term vlock in the console to block the session.
As we can see, it is very simple and practical to block our sessions using Vlock.
Some of the parameters that we can use when we use Vlock are the following:
Block the current session (we can also use -c instead of –current ).
Block the entire terminal, one or several sessions (we can use -a instead of –all ).
Open a new virtual console before blocking the user's current session (We can use -n).
Verify the current version of the vlock utility (We can use -v instead of –version ).
Display the help of Vlock (We can replace –help with -h ).
Finally, if we want to see all the login attempts or failed starts, we can use the following command to verify these values:
cat /var/log/auth.log | grep "vlock"
This command is very useful.
Vlock in Debian or Ubuntu environments
We have seen the characteristics of Vlock in CentOS or RHEL environments, but we will notice some small changes in the Debian or Ubuntu editions. In this case we will see Vlock in a Debian 8 environment.
The first noticeable change is the version of Vlock, while in CentOS or RHEL it is 1.15.5 in Debian or Ubuntu is 2.2.2.
In Vlock for Debian we will see that we have additional options such as:
vlock –timeout time_in_seconds
This option allows us to define the time in seconds before using the screen saver.
Using this option we can disable the SysRq mechanism while the virtual console is blocked. (We can use -s instead of –disable-sysrq ).
These are the novelties that Vlock has among these distros. Additionally we can see a small change in the blocking window:
RHEL and CentOS Environments
Debian or Ubuntu environment
As we have seen, thanks to this small utility we can secure our virtual consoles and prevent other users from accessing our user and making unauthorized changes or modifications that affect our credentials.
No matter the distribution we use, we will see that, although there are small modifications, the functionality is the same: Protect and block active sessions. Let's take advantage of this simple tool and have a safe environment.