If, like me, you don’t use a desktop environment but rather an ultra minimal window manager like DWM or Evil WM you may miss the same suspend-and-resume-to-screenlock seen in desktop environments (Ubuntu, OS X, Windows). This is how I’ve been doing it for 5 or so years:
I use xtrlock as my X11 screen-locker. It has a small install footprint, just 88K, and can be neatly integrated into your bash, zsh etc shell environment as an alias.
Install xtrlock and pm-suspend (Debian systems)
sudo apt-get install xtrlock pm-utils
Those not on Debian, look for xtrlock in your package manager or just grab and compile the source.
Allow for pm-suspend to be called by sudo without password
sudo visudo
Add the following to the end of the file. This is important. Replace “username” with the user you wish to give this functionality to:
username ALL= NOPASSWD: /usr/sbin/pm-suspend
Create an alias in your shell environment
I like to use ‘sx’ to suspend my laptop, such that when I close and open the lid again, I’m presented with the xtrlock screenlock. Just use echo to add it to the end of your file (assumes bash):
echo "alias sx='xtrlock & sudo pm-suspend'" >> ~/.bashrc
source ~/.bashrc
Enjoy.