If you are working on a sensitive project in the Linux terminal and need to step away from your computer, leaving your console unlocked is a massive security risk. While desktop environments (like GNOME or KDE) have simple GUI lock screens, securing a raw TTY virtual console or an SSH session is entirely different.
Logging out and logging back in works, but it kills all your running foreground processes. Instead, you can use a lightweight utility called vlock to instantly lock your active terminal session without closing any of your running tasks.
How to Install vlock
Before you can lock your terminal, you need to ensure the utility is installed. On most Debian and Ubuntu-based systems, it is included in the standard repositories.
Open your terminal and type the following command to install it:
sudo apt install vlock
How to Lock Your Active Terminal
Once installed, using the tool is incredibly simple.
- To lock the current terminal session, type:
vlock - Press Enter.
The screen will clear, and you will see a message stating that the terminal is locked. No commands can be entered, and no output from running processes will be displayed on the screen. Any background scripts or foreground processes you were running will continue to execute silently behind the lock screen.
How to Unlock the Terminal
When you return to your computer, press Enter to bring up the password prompt. Type your user account password and press Enter again. The terminal will instantly unlock, returning you exactly to where you left off.
Note: If you have root access and you lock the entire virtual console system using vlock -a, the system will not allow users to switch to other TTY consoles until the session is unlocked.