セッションをロック
セッションの画面をロックするユーティリティは数多くあります。ただし、使用するユーティリティは、使用している環境 (仮想コンソールまたは特定のディスプレイサーバー (Xorg または Wayland) に大きく依存することに注意して下さい。
環境別
仮想コンソール
vlock または physlock を使用して、仮想コンソールをロックできます。
Xorg
Xorg でセッションをロックするには多くの方法があるため、このセクションは不完全になる可能性があります。ただし、いくつかの方法には次のものがあります。
- xlockmore パッケージ内の
xlock - xsecurelock パッケージ内の
xsecurelock - xscreensaver パッケージの
xscreensaver-command -lock - xss-lock
- slock パッケージの中の slock
- kscreenlocker
- i3lock
- i3lock-colorAUR
- alockAUR
ほとんどのデスクトップ環境には、セッションをロックする何らかの方法が用意されています。
Wayland
swaylock または waylock でセッションをロックできます。
ロックのトリガー
セッションをロックするには、さまざまな方法があります。
- ターミナルから
- GUI を使用
- デスクトップアイコンから
- ホットコーナーの使用
- メニュー (マウスまたはキーボード操作) からを選択します
- ショートカット から
- イベントから
- 非アクティブ (systemd、xss-lock、xautolock を使用) イベントから
- systemd イベント (サスペンド、ハイバネートなど)
最後のポイント (イベントからロックをトリガーする) は、最も厄介です。
- アクショントリガーでロックを実行し、その後、最初のアクションを実行する。
- イベントトリガーから、イベントチェーンにロックを追加する。今のところ、これは systemd を使ってしかできません。
シェルトリガー
Zsh
ターミナルの非アクティブ後にコマンドを実行するには、環境変数 TMOUT を使用することができます。
ALARM 信号のトラップと組み合わせることで、ロックを実行することができます。トラップがなければ、シェルを終了させるだけです。
グラフィカルな環境にいるかどうかを検出したいかもしれません。そうでなければ、GUI ターミナルが理由もわからずに消え始めるかもしれません。
Xorg triggers
xss-lock
xss-lock is triggered by one of two things:
- systemd events
- DPMS
The advantage of this is that you can control a lock issued manually, by inactivity, and by a suspend command at the same place.
To execute an action on one of those events:
$ xss-lock <locker-utility>
systemd events
By default, xss-lock subscribes to suspend, hibernate, lock-session, and unlock-session with appropriate actions (run locker and wait for user to unlock or kill locker).
You can prevent xss-lock from being triggered by suspend and hibernate using --ignore-sleep.
You can trigger a manual lock using loginctl lock-session.
DPMS
To configure DPMS signaling timeout:
# Trigger screensaver after 10 minutes of inactivity xset s on xset s 600
DPMS signaling can also be configured in /etc/X11/xorg.conf.d/ in the Monitor section.
Using DPMS signaling, you can set a second timer, for example to notify the user or to dim the screen. For example (from xss-lock(1)):
# Dim the screen after three minutes of inactivity, lock the screen two minutes later using i3lock: xset s 180 120 xss-lock -n dim-screen.sh -- i3lock -n
An example dim-screen.sh script can be found in /usr/share/doc/xss-lock.
xautolock
$ xautolock -time 12 -locker "systemctl suspend" -detectsleep
- 1 min to 1 hour for
time - 10 min to 2 hour for
killtime
-detectsleep to prevent xautolock from locking the session after resuming. One nice feature of xautolock is the corners.Wayland triggers
swayidle
swayidle listens for idle activity from the Wayland compositor, as well as systemd events, and executes commands accordingly. See Sway#Idle.
D-Bus notification
Using loginctl lock-session, or the lock action in logind.conf(5), you can notify the system through DBUS that you want to lock. This notification can then be processed, for example by xss-lock.
Inactivity
In logind.conf(5), you can configure the IdleAction to lock. This will trigger a DBUS notification, that will have to be processed (for example by xsslock) to lock the session.
Note that this is for a global system (so this is not ideal for a multi user environment).
Note also that "this requires that user sessions correctly report the idle status to the system".
Units
Before suspend or hibernate
You can use a Sleep hook.
[Unit] Description=Lock the screen Before=sleep.target [Service] User=%I Type=forking Environment=DISPLAY=:0 ExecStart=/usr/bin/i3lock -c 000000 [Install] WantedBy=sleep.target
To enable it for a certain user, enable sleep@Username.service.
Lid closing
You can use the lock action using the related ACPI event.