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

Some problems you may encounter when installing MySQL

Question 1: When entering net start mysql during ...

Problems and experiences encountered in web development

<br />The following are the problems I encou...

Build Maven projects faster in Docker

Table of contents I. Overview 2. Conventional mul...

Docker compose custom network to achieve fixed container IP address

Due to the default bridge network, the IP address...

Simple steps to configure Nginx reverse proxy with SSL

Preface A reverse proxy is a server that receives...

Detailed explanation of the usage of 5 different values ​​of CSS position

The position property The position property speci...

A brief talk about MySQL semi-synchronous replication

Introduction MySQL achieves high availability of ...

Mybatis implements SQL query interception and modification details

Preface One of the functions of an interceptor is...

JavaScript to achieve the effect of clicking on the self-made menu

This article shares the specific code of JavaScri...

Detailed explanation of the loop form item example in Vue

Sometimes we may encounter such a requirement, th...

MySQL full-text fuzzy search MATCH AGAINST method example

MySQL 4.x and above provide full-text search supp...

HTML table markup tutorial (2): table border attributes BORDER

By default, the border of the table is 0, and we ...

Detailed steps for deploying Microsoft Sql Server with Docker

Table of contents 1 Background 2 Create a contain...