Implementation of locking a virtual console session on Linux

  • 2020-12-16 06:18:44
  • OfStack

When you're working on a shared system, you probably don't want other users peeping into your console to see what you're doing. If so, I know that there is a simple trick to locking your own session while still allowing other users to use the system on other virtual consoles. Would like to thank Vlock(Virtual Console lock) , a command line program that locks one or more sessions on the Linux console. If necessary, you can lock the entire console and disable virtual console toggle completely. Vlock is particularly useful for shared Linux systems with multiple users accessing the console.

Install Vlock

On Arch-based systems, the Vlock package is replaced with the default pre-installed kpd package, so you don't have to worry about installation.

On Debian, Ubuntu, Linux Mint, run the following command to install Vlock:


$ sudo apt-get install vlock

On the Fedora:


$ sudo dnf install vlock

On RHEL and CentOS:


$ sudo yum install vlock

Lock the virtual console session on Linux

The general grammar of Vlock is:


vlock [ -acnshv ] [ -t <timeout> ] [ plugins... ]

Here:

a -- Lock all virtual console sessions, c -- Locks the current virtual console session, n -- Switch to a new empty console before locking all sessions, s -- Disable the SysRq key mechanism, t -- Specifies the timeout period for the screensaver plug-in, h -- Show help, v - Display version.

Let me give you a few examples.

1. Lock the current console session

When Vlock is run without any parameters, it locks the current console session (TYY) by default. To unlock the session, you need to enter the current user's password or root password.

$ vlock

You can also use the -c flag to lock the current console session.

$ vlock -c

Note that this command locks only the current console. You can press ALT+F2 to switch to another console. For more details on switching between TTY, see the following guidelines.

In addition, if the system has multiple users, other users can still access their respective TTY.

2. Lock all console sessions

To lock all TTY at the same time and disable virtual console switching, run:

$ vlock -a

Again, to unlock the console session, simply press enter and enter the current user's password or root user password.

Keep in mind that root users can unlock any vlock session at any time, unless disabled at compile time.

3. Switch to a new virtual console before locking all consoles

You can also make Vlock switch from the X session to the new empty virtual console before locking all consoles. To do this, use the -ES94en flag.

$ vlock -n

4. Disable SysRq mechanism

As you may know, the Magic SysRq key mechanism allows the user to perform certain actions when the system crashes. Thus, users can unlock the console using SysRq. To prevent this, pass the -s option to disable the SysRq mechanism. Keep in mind that this option only works if you have the -a option.

$ vlock -sa

See the Help or man page for more options and their usage.

$ vlock -h
$ man vlock

Vlock prevents unauthorized users from gaining access to the console. If you're looking for a simple console locking mechanism for Linux, then Vlock is worth a try!

conclusion


Related articles: