https://wiki.archlinux.org/api.php?action=feedcontributions&user=Cholin&feedformat=atomArchWiki - User contributions [en]2024-03-29T00:54:41ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Session_lock&diff=591257Session lock2019-12-08T14:28:42Z<p>Cholin: Fix and extend unit file (Type=forking was missing)</p>
<hr />
<div>[[Category:Security]]<br />
There are numerous utilities to lock the screen of a session. But it is important to note that the utility to use is highly dependant on the environment your are in, either the virtual console, or a specific display server (Xorg or Wayland).<br />
<br />
See [[List_of_applications#Screen_lockers|List of screen lockers]].<br />
<br />
== By environment ==<br />
<br />
=== Virtual Console ===<br />
<br />
You can use {{ic|vlock}} to lock a virtual console.<br />
<br />
=== Xorg ===<br />
{{Expansion}}<br />
<br />
=== Wayland ===<br />
{{Expansion}}<br />
<br />
== Triggering the lock ==<br />
<br />
You can lock a session using different methods:<br />
* from a terminal<br />
* using a GUI:<br />
** from a desktop icon<br />
** using hot corners<br />
** from a menu (mouse or keyboard driven)<br />
* from a [[Keyboard shortcuts|shortcut]]<br />
* from an event:<br />
** inactivity<br />
** another action (suspend, hibernate, ...)<br />
<br />
The last point (triggering a lock from an event) is the trickiest, because you can do it one of two ways:<br />
* get the action trigger to execute your lock, then to execute the initial action.<br />
* from the event trigger, add the lock to the event chain. So far this can only be done using systemd.<br />
<br />
=== List of triggers ===<br />
==== Manual ====<br />
<br />
==== Inactivity ====<br />
<br />
You can trigger a lock on inactivity using [[#Inactivity_2|systemd]], [[DPMS]] (see [[#xss-lock|xss-lock]]) or [[#xautolock|xautolock]]<br />
<br />
==== Suspend / Hibernate ====<br />
See systemd<br />
Service file dependency<br />
Hook to xss-lock<br />
<br />
=== Shell triggers ===<br />
<br />
==== ZSH ====<br />
<br />
To execute a command after terminal inactivity, you can use the TMOUT environment variable.<br />
<br />
You can combine it with a trap on the ALARM signal to execute the lock. Without a trap, it will just terminate the shell.<br />
<br />
You might want to detect if you are in a graphical environments, otherwise your GUI terminals might start disappearing without you understanding why. <br />
<br />
=== Xorg triggers ===<br />
<br />
==== xss-lock ====<br />
<br />
{{pkg|xss-lock}} is triggered by one of two things:<br />
* systemd events<br />
* [[DPMS]]<br />
<br />
The advantage of this is that you can control a lock issued manually, by inactivity, and by a suspend command at the same place.<br />
<br />
To execute an action on one of those events:<br />
{{bc|<br />
xss-lock <locker-utility><br />
}}<br />
<br />
===== systemd events =====<br />
<br />
By default, xss-lock subscribes to {{ic|suspend}}, {{ic|hibernate}}, {{ic|lock-session}}, and {{ic|unlock-session}} with appropriate actions (run locker and wait for user to unlock or kill locker).<br />
<br />
You can prevent xss-lock from being triggered by {{ic|suspend}} and {{ic|hibernate}} using {{ic|--ignore-sleep}}.<br />
<br />
You can trigger a manual lock using loginctl lock-session.<br />
<br />
===== DPMS =====<br />
<br />
To configure DPMS signaling timeout:<br />
{{bc|<br />
# Trigger screensaver after 10 minutes of inactivity<br />
xset s on<br />
xset s 600<br />
}}<br />
DPMS signaling can also be configured in {{ic|/etc/X11/xorg.conf.d/}} in the {{ic|Monitor}} section.<br />
<br />
Using DPMS signaling, you can set a second timer, for example to notify the user or to dim the screen.<br />
For exemple (from {{man|1|xss-lock}}):<br />
{{bc|<br />
# Dim the screen after three minutes of inactivity, lock the screen two minutes later using i3lock:<br />
<br />
xset 180 120<br />
xss-lock -n dim-screen.sh -- i3lock -n<br />
}}<br />
<br />
{{Note|<br />
When using xss-lock with [[DPMS]], you will have to blank the screen yourself.<br />
It will not be triggered when looking at videos<br />
}}<br />
<br />
==== xautolock ====<br />
<br />
{{bc|<br />
xautolock -time 12 -locker "systemctl suspend" -detectsleep<br />
}}<br />
<br />
{{Note|<br />
xautolock has restrictive timer limits:<br />
* 1 min to 1 hour for {{ic|time}}<br />
* 10 min to 2 hour for {{ic|killtime}}<br />
It might be necessary to add {{ic|-detectsleep}} to prevent xautolock from locking the session after resuming.<br />
One nice feature of xautolock is the {{ic|corners}}.<br />
}}<br />
<br />
=== Wayland triggers ===<br />
{{Expansion}}<br />
<br />
=== SystemD triggers ===<br />
<br />
==== DBUS Notification ====<br />
<br />
Using {{ic|loginctl lock-session}}, or the {{ic|lock}} action in {{man|5|logind.conf}}, you can notify the system through DBUS that you want to lock. This notification can the be processed, for exemple by xss-lock.<br />
<br />
==== Inactivity ====<br />
<br />
In {{man|5|logind.conf}}, you can configure the {{ic|IdleAction}} to {{ic|lock}}. This will trigger a DBUS notification, that will have to be processed (for exemple by xsslock) to lock the session.<br />
<br />
Note that this is for a global system (so this is not ideal for a multi user environment).<br />
<br />
Note also that "this requires that user sessions correctly report the idle status to the system".<br />
<br />
==== Units ====<br />
<br />
===== Before suspend/hibernate =====<br />
<br />
You can use a [[Power_management#Sleep_hooks|Sleep hook]].<br />
<br />
{{bc|1=<br />
[Unit]<br />
Description=Lock the screen<br />
Before=sleep.target<br />
<br />
[Service]<br />
User=%I<br />
Type=forking<br />
Environment=DISPLAY=:0<br />
ExecStart=/usr/bin/i3lock -c 000000<br />
<br />
[Install]<br />
WantedBy=sleep.target<br />
}}<br />
<br />
To enable it for a certain user, use {{ic|systemctl enable sleep@USERNAME}}.<br />
<br />
===== Lid closing =====<br />
<br />
You can use the {{ic|lock}} action using the related [[Power_management#ACPI_events|ACPI Event]]<br />
<br />
== Actions after the lock has been triggered ==<br />
<br />
Suspend/Hibernate after X<br />
Shudown screen<br />
<br />
== See also ==<br />
<br />
* [https://geoff.greer.fm/2018/01/02/linux-laptop-locking/ Geoff Greer's site: Linux Laptop Locking]</div>Cholinhttps://wiki.archlinux.org/index.php?title=Lenovo_ThinkPad_X220&diff=247411Lenovo ThinkPad X2202013-02-15T13:26:35Z<p>Cholin: /* Heat issues */</p>
<hr />
<div>[[Category:Lenovo]]<br />
{{Stub}}<br />
<br />
== Setup ==<br />
=== Graphics ===<br />
The graphic card is supported by the xf86-video-intel driver package from the extra repository. The Xorg server makes use of this automatically. There's no need for a Xorg configuration file.<br />
pacman -S xf86-video-intel<br />
<br />
== Configuration ==<br />
<br />
=== Heat issues ===<br />
<br />
According to a [https://bbs.archlinux.org/viewtopic.php?pid=1030495#p1030495 forum post] you should set some power saving options in '''/etc/modprobe.d/modprobe.conf''' or add them to your ''kernel'' line in your '''menu.lst'''. We use rc6=7 for deepest sleep mode.<br />
options i915 modeset=1<br />
options i915 i915_enable_rc6=7<br />
options i915 i915_enable_fbc=1 <br />
options i915 lvds_downclock=1<br />
<br />
As well you could suffer of [https://bbs.archlinux.org/viewtopic.php?id=150743 Kernel Power Regressions].<br />
<br />
==See also==<br />
* Arch user blogs about the X220 <br />
** [http://natalian.org/archives/2011/11/10/Thinkpad_X220/ Thinkpad X220 model 4287CTO] using a msata SSD for 64 bit Archlinux<br />
** [http://blog.jamiek.it/2011/10/arch-linux-on-thinkpad-x220.html X220 i5]<br />
* [http://www.thinkwiki.org/wiki/Category:X220 Thinkwiki X220 reference]<br />
* [https://bbs.archlinux.org/viewtopic.php?id=129885 "Arch By Hand" UEFI GPT SSD LUKS Install Script], built on an x220 tablet with an SSD.<br />
* [http://forum.notebookreview.com/lenovo-ibm/575569-linux-x220-29.html#post8075286 Power saving options for the X220 - Notebook Review Forum]</div>Cholinhttps://wiki.archlinux.org/index.php?title=Lenovo_ThinkPad_X220&diff=243193Lenovo ThinkPad X2202013-01-07T21:09:28Z<p>Cholin: </p>
<hr />
<div>[[Category:Lenovo]]<br />
{{Stub}}<br />
<br />
== Setup ==<br />
=== Graphics ===<br />
The graphic card is supported by the xf86-video-intel driver package from the extra repository. The Xorg server makes use of this automatically. There's no need for a Xorg configuration file.<br />
pacman -S xf86-video-intel<br />
<br />
== Configuration ==<br />
<br />
=== Heat issues ===<br />
<br />
According to a [https://bbs.archlinux.org/viewtopic.php?pid=1030495#p1030495 forum post] you should set some power saving options in '''/etc/modprobe.d/modprobe.conf''' or add them to your ''kernel'' line in your '''menu.lst'''.<br />
options i915 modeset=1<br />
options i915 i915_enable_rc6=1 <br />
options i915 i915_enable_fbc=1 <br />
options i915 lvds_downclock=1<br />
<br />
As well you could suffer of [https://bbs.archlinux.org/viewtopic.php?id=150743 Kernel Power Regressions].<br />
==See also==<br />
* Arch user blogs about the X220 <br />
** [http://natalian.org/archives/2011/11/10/Thinkpad_X220/ Thinkpad X220 model 4287CTO] using a msata SSD for 64 bit Archlinux<br />
** [http://blog.jamiek.it/2011/10/arch-linux-on-thinkpad-x220.html X220 i5]<br />
* [http://www.thinkwiki.org/wiki/Category:X220 Thinkwiki X220 reference]<br />
* [https://bbs.archlinux.org/viewtopic.php?id=129885 "Arch By Hand" UEFI GPT SSD LUKS Install Script], built on an x220 tablet with an SSD.<br />
* [http://forum.notebookreview.com/lenovo-ibm/575569-linux-x220-29.html#post8075286 Power saving options for the X220 - Notebook Review Forum]</div>Cholin