Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu + i3lock lock on lid close [closed]

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 :)

like image 467
boogie666 Avatar asked Jan 28 '17 12:01

boogie666


People also ask

How do I keep Ubuntu from going to sleep when I close the lid?

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.

When lid is closed Ubuntu?

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.

How do I lock the lid switch in Ubuntu without UI?

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.

What happens when laptop lid is closed in Ubuntu?

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.

How to lock hibernate in Ubuntu 20 04?

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.

How do I lock a file when the lid is closed?

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.


1 Answers

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

like image 75
boogie666 Avatar answered Sep 19 '22 02:09

boogie666