How to lock a virtual console session on Linux

How to lock a virtual console session on Linux

When you are working on a shared system, you probably don't want other users to be able to peek into your console and see what you are doing. If so, I know of a simple trick to lock my own session while still allowing other users to use the system on other virtual consoles. Thanks to Vlock(Virtual Console lock) , a command-line program for locking one or more sessions on a Linux console. If necessary, you can lock the entire console and disable the virtual console switching feature entirely. Vlock is particularly useful on shared Linux systems where multiple users have access to the console.

Install Vlock

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

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

$ sudo apt-get install vlock

On Fedora:

$ sudo dnf install vlock

On RHEL, CentOS:

$ sudo yum install vlock

Locking a Virtual Console Session on Linux

The general syntax of Vlock is:

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

here:

  • a - locks all virtual console sessions,
  • c - lock 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 of the screen saver plug-in,
  • h - show help,
  • v —— Display version.

Let me give you some examples.

1. Lock the current console session

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

$ vlock

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

$ vlock -c

Note that this command only locks the current console. You can switch to another console by pressing ALT+F2. For more details on switching between TTYs, see the following guides.

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 simultaneously and disable virtual console switching, run:

$ vlock -a

Likewise, to unlock the console session, just press Enter and enter the current user's password or the root user password.

Remember that the root user 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 an X session to a new empty virtual console before locking all consoles. To do this, use the -n 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 freezes. Therefore, the user can unlock the console using SysRq. To prevent this, pass the -s option to disable the SysRq mechanism. Remember that this option only works with the -a option.

$ vlock -sa

For more options and their usage, see the help or man pages.

$ 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, Vlock is worth a try!

Summarize

The above is the implementation method of locking the virtual console session on Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Linux basics: terminal, console, tty, pty introduction
  • Implementing 2048 mini game under Linux console
  • Website console directadmin Chinese manual virtual host management under Linux

<<:  Implementation of Webpack3+React16 code splitting

>>:  MySQL 5.6.33 installation and configuration tutorial under Linux

Recommend

Detailed process of upgrading glibc dynamic library in centos 6.9

glibc is the libc library released by gnu, that i...

How to dynamically add ports to Docker without rebuilding the image

Sometimes you may need to modify or add exposed p...

Use of docker system command set

Table of contents docker system df docker system ...

MySQL 5.7.18 installation tutorial under Windows

This article explains how to install MySQL from a...

MySQL index usage instructions (single-column index and multi-column index)

1. Single column index Choosing which columns to ...

Web designers also need to learn web coding

Often, after a web design is completed, the desig...

Implementation of Docker private warehouse registry deployment

As more and more Docker images are used, there ne...

Solution to occasional crash of positioning background service on Linux

Problem Description In the recent background serv...

Detailed explanation of how to install MySQL on Alibaba Cloud

As a lightweight open source database, MySQL is w...

CSS3 achieves flippable hover effect

CSS3 implements a flippable hover effect. The spe...

VMware ESXI server virtualization cluster

Table of contents summary Environment and tool pr...

JavaScript Dom implements the principle and example of carousel

If we want to make a carousel, we must first unde...