I generally want my laptop to be locked when it's suspended but not when I just suspended it because there is a use case in which entering my password after my laptop woke up from suspend is pretty cumbersome. A good compromise is to only require the login password if the laptop was suspended more than 10 minutes ago. How do I do this?
I use Ubuntu 16.04 with Unity.
Create a file within
/lib/systemd/system-sleep/
, named e.g:lightdm
:make this file executable:
Every time you "suspend" or "resume" your Ubuntu, this script going to be run.
Open it using your desired text editor, e.g:
sudo nano /lib/systemd/system-sleep/lightdm
, and paste this lines into it and then save it:What it does?
When you are putting your Ubuntu into "sleep" mode this script will save current timestamps, then while resuming system it will check old timestamps with the current one, if the different was more that "600" second (10 Minuets) it's going to show you "lightdm" lock screen otherwise it does nothing.
For the last step:
open "system settings" -> "Brightness & lock". Disable asking password after waking up from suspend, because we leave handling the lock screen to the script.
After reboot or shutdown you still need to enter your password.
Add a script in
/lib/systemd/system-sleep/
to unlock your session if system was suspended for a short time:With this content:
I can help you with this. First, go to settings. Select this setting:
There will be a drop down menu that says Screen Turns Off.
After clicking on the drop down menu change both settings so they look like this: