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

How to connect to docker server using ssh

When I first came into contact with docker, I was...

Detailed explanation of the pitfalls of nginx proxy socket.io service

Table of contents Nginx proxies two socket.io ser...

Two methods to disable form controls in HTML: readonly and disabled

In the process of making web pages, we often use f...

How to configure CDN scheduling using Nginx_geo module

Introducing the Geo module of Nginx The geo direc...

Example operation MySQL short link

How to set up a MySQL short link 1. Check the mys...

Mysql specifies the date range extraction method

In the process of database operation, it is inevi...

Various ways to achieve the hollowing effect of CSS3 mask layer

This article introduces 4 methods to achieve mask...

Example code for circular hover effect using CSS Transitions

This article introduces Online preview and downlo...

Detailed installation process of mysql5.7.21 under win10

This article shares the installation of MySQL 5.7...

Detailed explanation of JavaScript's Set data structure

Table of contents 1. What is Set 2. Set Construct...

The difference between useEffect and useLayoutEffect in React

Table of contents Prerequisites useEffect commitB...

How to load third-party component libraries on demand in Vue3

Preface Take Element Plus as an example to config...

mysql startup failure problem and scenario analysis

1. One-stop solution 1. Problem analysis and loca...