I looking to lock my laptop when i close the lid and can't get this working in Ubuntu 16.04.
I've tried this https://github.com/ruudud/i3wm-scripts
seems that this is the solution most commonly suggested on the internet, but it does not work.
The github repo suggests creating a service called i3lock.service that runs (as far as i can tell) before "sleep.target". Please note that i have no clue what that is, and would appreciate some more info about that.
I'm not sure if i'm supposed to just create the file and it should work or it requires some special privileges for that file or what? More detail on that would be needed.
If this solution is incorrect is it possible to be pointed to a better solution to this problem?
Thank you in advance :)
Open the Activities overview and start typing Tweaks. Click Tweaks to open the application. Select the General tab. Switch the Suspend when laptop lid is closed switch to off.
HandleLidSwitch=poweroff – Whenever the lid will be closed, Ubuntu 20.04 system will be locked shut down automatically. HandleLidSwitch=hibernate – Whenever the lid will be closed, Ubuntu 20.04 system will be locked hibernate automatically.
For Ubuntu server without UI, use nano text editor instead. 2.) When the file opens, find out the line #HandleLidSwitch=suspend and change it to one of following : HandleLidSwitch=lock – lock when lid closed. HandleLidSwitch=ignore – do nothing.
When laptop lid is closed in Ubuntu 20.04, it suspends Ubuntu by default. In this tutorial, we are going to configure this default lid close behavior in Ubuntu 20.04 LTS. We are going to tweak the logind.conf file to change the action of lid in Ubuntu.
HandleLidSwitch=hibernate – Whenever the lid will be closed, Ubuntu 20.04 system will be locked hibernate automatically. We have another option as HandleSuspendKey=Suspend. We are going to use it in the following way.
Type user password (no asterisk feedback) and hit Enter. For Ubuntu server without UI, use nano text editor instead. 2.) When the file opens, find out the line #HandleLidSwitch=suspend and change it to one of following : HandleLidSwitch=lock – lock when lid closed.
In the mean time I switched to Manjaro (much nicer), but this solution should work on both:
Creating a service called [email protected]
in /etc/systemd/system
with this content:
[Unit]
Description=i3lock on suspend
After=sleep.target
[Service]
User=%i
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/locker
[Install]
WantedBy=sleep.target
Makeing it executable
chmod +x [email protected]
Then enableing it for your user
systemctl enable lock@<username>.service
should do the trick.
Note that the %i in User=%i will be replaced with the <username>
.
The "/usr/bin/locker" could just be /usr/bin/i3lock but i have some fancy stuff added there to make it look good.
Hope this helps some body at some point
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With