This feature is native to MacOS, but you need to activate it first.
Enable password protection for the screen saver:
- From the Apple menu > System Preferences > Security and Privacy.
- In the "General" tab: check the "Require password" and "immediately".
- As from now the keyboard short-cut to launch the screen saver (CTRL-SHIFT-EJECT) will lock the Mac: you will need to enter your user password to unlock it.
This document, titled « MacOS - A keyboard shortcut to rapidly lock your screen », is available under the Creative Commons
license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM