What Are the Commands to Lock a Computer: Windows, macOS, and Linux Explained
Knowing the commands to lock a computer is one of those small skills that can protect your privacy, your files, and even your job. Whether you step away for coffee, leave your desk in a shared office, or simply want to automate security, a proper lock command keeps your session safe without closing your open programs. This guide covers every practical method: keyboard shortcuts, command-line instructions, PowerShell scripts, and automatic locking for Windows, macOS, and Linux.
Why Locking Your Computer Matters
Locking your screen keeps your user session running in memory while blocking access to the display. That means your browser tabs, documents, and downloads stay exactly where you left them, but nobody can see your email, files, or saved passwords.
- It prevents shoulder surfing in public or shared spaces.
- It stops colleagues, roommates, or strangers from opening your accounts.
- It satisfies many workplace security policies and compliance rules.
- It protects you from quick, opportunistic tampering — not just sophisticated hackers.
The golden rule: lock whenever you walk away, even for a minute.
Lock Commands for Windows
The Fastest Method: Keyboard Shortcut
Press Win + L. On the flip side, that's it. This is the official Microsoft shortcut and works on Windows 7, 8, 10, and 11.
Other Windows options:
- Ctrl + Alt + Delete, then choose Lock.
- Ctrl + Win + L on some keyboards (depends on the manufacturer).
- Click your Start menu → user icon → Lock.
The Command-Line Way
Windows does not have a simple lock.exe. Instead, you call a function inside `user32 Not complicated — just consistent..
rundll32.exe user32.dll,LockWorkStation
Paste that into Command Prompt, PowerShell, or the Run dialog (Win + R) and your screen locks instantly. This is the most reliable built-in command and works on nearly every modern Windows version.
Other useful variations:
tsdiscon— disconnects a Remote Desktop session, effectively locking it.shutdown /l— logs you off, which is not the same as locking. Use it only if you want to close everything.
Create a One-Click Lock Shortcut
- Right-click the desktop → New → Shortcut.
- Enter `rundll32