Home Command line utilities How To Lock Virtual Console Sessions On Linux

How To Lock Virtual Console Sessions On Linux

By sk
Published: Last Updated on 2.7K views

When you're working on a shared system, you might not want the other users to sneak peak in your console to know what you're actually doing. If so, I know a simple trick to lock your own session while still allowing other users to use the system on other virtual consoles. Thanks to Vlock, stands for Virtual Console lock, a command line program to lock one or more sessions on the Linux console. If necessary, you can lock the entire console and disable the virtual console switching functionality altogether. Vlock is especially useful for the shared Linux systems which have multiple users with access to the console.

Installing Vlock

On Arch-based systems, the Vlock package is replaced with kpd package which is preinstalled by default, so you need not to bother with installation.

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

$ sudo apt-get install vlock

On Fedora:

$ sudo dnf install vlock

On RHEL, CentOS:

$ sudo yum install vlock

Lock Virtual Console Sessions On Linux

The general syntax for Vlock is:

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

Where,

  • a - Lock all virtual console sessions,
  • c - Lock current virtual console session,
  • n - Switch to new empty console before locking all sessions,
  • s - Disable SysRq key mechanism,
  • t - Specify the timeout for the screensaver plugins,
  • h - Display help section,
  • v - Display version.

Let me show you some examples.

1. Lock current console session

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

$ vlock
Lock current virtual console session

Lock current virtual console session

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

$ vlock -c

Please note that this command will only lock the current console. You can switch to other consoles by pressing ALT+F2. For more details about switching between TTYs, refer the following guide.

Also, if the system has multiple users, the other users can still access their respective TTYs.

2. Lock all console sessions

To lock all TTYs at the same time and also disable the virtual console switching functionality, run:

$ vlock -a
Lock all virtual consoles

Lock all virtual consoles

Again, to unlock the console sessions, just press ENTER key and type your current user's password or root user password.

Please keep in mind that the root user can always unlock any vlock session at any time, unless disabled at compile time.

3. Switch to new virtual console before locking all consoles

It is also possible to make Vlock to switch to new empty virtual console from X session before locking all consoles. To do so, use -n flag.

$ vlock -n

4. Disable SysRq mechanism

As you may know, the Magic SysRq key mechanism allows the users to perform some operations when the system freeze. So the users can unlock the consoles using SysRq. In order to prevent this, pass the -s option to disable SysRq mechanism. Please remember, this only works if the -a option is given.

$ vlock -sa

For more options and its usage, refer the help section or the man pages.

$ vlock -h
$ man vlock

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


Suggested read:


Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More