4.5. Laptop and Desktop Session Management

A desktop session is more than a running window manager. logind owns the seat and tracks the session, a per-user service manager starts the user's daemons, and separate services handle power policy, Bluetooth, secret storage, screen locking, accessibility, and network control. Each service has its own D-Bus name, unit, configuration, and failure mode. A locked keyring does not stop the panel from drawing, and an unmanaged network interface does not stop the session from starting, but both can make the desktop appear broken.

Services attached to a desktop session

Figure 4.6. Conceptual session services. The display manager starts the session and logind tracks it; keyring, locker, power, audio, accessibility, and network are separate per-user or system services.

4.5.1. Power Profiles, Suspend, and Hibernation Requirements

power-profiles-daemon exposes a small set of platform power profiles to the desktop. A profile is a policy hint: it can change CPU scaling, platform settings, or device behavior when the hardware and kernel driver support it. List the available profiles and the current one:

$ powerprofilesctl list
* balanced:
    PlatformDriver: placeholder

  power-saver:
    PlatformDriver: placeholder

balanced is marked current, and placeholder is the daemon's way of saying that no real platform driver is controlling hardware on this virtual machine. The command forms are:

powerprofilesctl form Description
list List profiles, the current profile, and the platform driver.
get Print the active profile.
set PROFILE Switch to an available profile.
launch COMMAND Run a command under a temporary profile, when supported.
$ powerprofilesctl get
balanced

Switching profiles needs the service's authorization; from john's shell the elevated form is silent, and a separate query confirms the change:

$ sudo powerprofilesctl set power-saver
$ powerprofilesctl get
power-saver

Restore the original profile, which is also silent:

$ sudo powerprofilesctl set balanced

The daemon offered only balanced and power-saver here; a laptop with a supported Intel or AMD platform commonly exposes performance as well. The available choices come from the daemon and the platform, not from a fixed list, a profile change does not override a firmware thermal limit, and a hot or throttled machine needs investigation rather than a profile switch.

Sleep states are a kernel and firmware matter. /sys/power/state lists the states the kernel can attempt:

$ cat /sys/power/state
freeze mem disk

freeze is suspend-to-idle, mem is suspend-to-RAM, and disk is hibernation. The list means the kernel recognizes the names; it does not guarantee that the firmware and every device will enter and leave the state correctly.

State Name Main requirement How to check
freeze Suspend-to-idle Kernel and device drivers that support idle; no swap is required cat /sys/power/state; try systemctl suspend at a local console
mem Suspend-to-RAM Firmware and platform support for S3 or an equivalent sleep state cat /sys/power/state; confirm resume and device state in the kernel log
disk Hibernation Suitable swap and a working resume configuration sudo swapon --show; systemctl hibernate and verify the resume path

Hibernation additionally needs swap space large enough to hold the hibernation image and a resume configuration that lets the kernel find it. The example machine has no swap at all - swapon --show prints nothing - so a hibernation request fails before writing an image:

$ sudo swapon --show
$ sudo systemctl hibernate
Call to Hibernate failed: Not enough suitable swap space for hibernation available on compatible block devices and file systems

This failure is informative: the request reached the hibernation logic, and the kernel rejected it for lack of suitable swap. It does not prove that hibernation would work after adding swap. A hibernation image is written to swap and read back by the early boot code, so the kernel must locate that swap before mounting the root filesystem: a swap partition is identified with resume= on the kernel command line, a swap file additionally needs a resume_offset, the initramfs must contain the storage driver needed to reach it, and encrypted swap must have its key available at resume time. Those requirements, and the storage design behind them, are covered in Chapter 11 and Chapter 13; adding a swap file without checking the resume path does not produce working hibernation.

Warning: Do not test suspend or hibernation on a machine whose only access is the network. A failed resume can leave the machine unreachable even though the kernel accepted the request.

On a laptop, use the desktop's power menu or systemctl suspend at a local console, confirm that the machine resumes, and check the kernel log for device errors afterward. The example machine is administered over SSH, so suspend was not attempted. Lid and idle behavior is configured in /etc/systemd/logind.conf through HandleLidSwitch, HandleLidSwitchExternalPower, IdleAction, and IdleActionSec; these are persistent system settings, and after editing the file a restart of systemd-logind applies them, which can affect active sessions.

4.5.2. Bluetooth Pairing and Troubleshooting

BlueZ provides the Bluetooth stack and the bluetoothd daemon. A controller appears as an hci device, and bluetoothctl is the command-line client for discovery, pairing, trust, and connection. The example machine has no Bluetooth radio, so this section uses the kernel's virtual HCI driver and BlueZ's btvirt emulator from bluez-test-tools to exercise controller discovery, power state, and the command interface; it cannot complete a pairing with a real remote device.

Start the service and load the virtual HCI module. Both commands are silent:

$ sudo systemctl start bluetooth
$ sudo modprobe hci_vhci

btvirt -l2 creates two emulated controllers. The inner sh -c wrapper keeps the background process attached to root's redirection while the outer command returns immediately, and nohup detaches it from the terminal:

$ sudo sh -c "nohup btvirt -l2 >/var/log/ch04-btvirt.log 2>&1 &"

List the controllers BlueZ now knows. The default controller here was 00:AA:01:01:00:01; the emulator can assign the default differently, so read the addresses from the output rather than assuming an order:

$ bluetoothctl list
Controller 00:AA:01:01:00:01 trixie #2 [default]
Controller 00:AA:01:00:00:00 trixie
$ bluetoothctl show | head -12
Controller 00:AA:01:01:00:01 (public)
    Manufacturer: 0x05f1 (1521)
    Version: 0x09 (9)
    Name: trixie #2
    Alias: trixie #2
    Class: 0x00400000 (4194304)
    Powered: yes
    PowerState: on
    Discoverable: no
    DiscoverableTimeout: 0x000000b4 (180)
    Pairable: no
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)

Powering the controller off and on exercises the BlueZ state transitions. Selected output; the kernel-side hci1 notification lines are omitted, and BlueZ's color escapes are not reproduced:

$ bluetoothctl power off
Changing power off succeeded

Selected output from the same exercise, with the same omissions:

$ bluetoothctl power on
Changing power on succeeded

A bounded scan starts discovery and returns after five seconds; the --timeout option belongs to bluetoothctl itself. The capture's Discovering: yes change notification is omitted here:

$ bluetoothctl --timeout 5 scan on
SetDiscoveryFilter success
Discovery started

On hardware, discovered devices appear while the scan is active. Here the listing after the scan is empty, which the command reports by printing nothing:

$ bluetoothctl devices

The emulated controllers have no peer that can answer a pairing request, so asking to pair with one of their addresses fails with a specific message and exit status 1:

$ bluetoothctl pair 00:AA:01:00:00:00
Device 00:AA:01:00:00:00 not available

not available means BlueZ does not currently see a remote device with that address; it is not a generic "Bluetooth is broken" error. On real hardware the pairing sequence is: make the device discoverable, scan on until it appears in bluetoothctl devices, pair ADDRESS, then trust ADDRESS so the controller reconnects to it automatically, and connect ADDRESS when the profile needs an explicit connection.

bluetoothctl command Description
list List controllers known to BlueZ.
show [controller] Show the selected controller's properties.
power on / power off Change the controller's radio state.
scan on / scan off Start or stop discovery.
devices List discovered devices.
pair ADDRESS Pair with a device.
trust ADDRESS Mark a device as trusted for future connections.
connect ADDRESS Connect to a paired device.
remove ADDRESS Remove a device and its pairing information.

Audio devices add another layer: after a headset is paired, PipeWire and WirePlumber must expose its A2DP or HFP/HSP profile, and the desktop's sound settings select it as an output or input. Keyboards and mice use the HID profile and usually need to be trusted before they reconnect automatically. A device that pairs but does not connect is a profile, firmware, or adapter problem rather than a pairing failure.

The emulated controllers exist only while btvirt runs and hci_vhci is loaded. Stop the emulator and unload the test module when the exercise is finished; all three commands are silent, and none of them is needed for a real adapter:

$ sudo pkill btvirt
$ sudo systemctl stop bluetooth
$ sudo modprobe -r hci_vhci

When no controller appears on real hardware, check that the kernel detected the adapter and that the radio is not blocked: rfkill list bluetooth reports soft and hard block states, rfkill unblock bluetooth clears a soft block, and a hard block is a firmware or physical switch. Also check systemctl status bluetooth, the kernel log for firmware loading errors, and bluetoothctl show for a powered controller. Some adapters need firmware from a non-free-firmware package such as firmware-realtek; installing the desktop's Bluetooth panel does not install the adapter firmware.

4.5.3. Keyrings, Screen Locking, and Accessibility

A desktop keyring stores secrets such as Wi-Fi passwords, browser saved passwords, and application tokens. GNOME Keyring implements the Secret Service D-Bus API; libsecret is the client library and secret-tool its command-line frontend, installed as libsecret-tools. On a desktop the login keyring is unlocked with the user's password through PAM when the graphical session starts; if the keyring password differs from the login password, the desktop asks for the keyring password separately.

The exercise below runs in a private D-Bus session with its own temporary keyring, so it demonstrates the store, lookup, and clear operations without touching a real login keyring. Save the following script in the workspace as keyring-test.sh, using the terminal-editor basics from Chapter 3; the eval line starts the keyring daemon, feeds it an unlock password on standard input, and exports the daemon's environment into the script:

#!/bin/sh
set -eu
eval "$(printf %s ch04pass | gnome-keyring-daemon --unlock --components=secrets)"
printf %s s3cret | secret-tool store --label=ch04test service ch04
printf 'STORE=%s\n' "$?"
secret-tool lookup service ch04
printf '\nLOOKUP=%s\n' "$?"
secret-tool clear service ch04
printf 'CLEAR=%s\n' "$?"

Make it executable, which is silent, then run it inside a private session bus:

$ chmod +x /home/john/debian-handbook/desktop-baseline/keyring-test.sh
$ dbus-run-session -- /home/john/debian-handbook/desktop-baseline/keyring-test.sh
STORE=0
s3cret
LOOKUP=0
CLEAR=0

Each stage succeeded with status 0: the secret s3cret was stored under the attribute pair service ch04, printed again by lookup, and removed by clear. The attributes are the keyring's lookup index, so use stable, descriptive pairs; both scripts send the secret on standard input, which keeps it out of the process argument list. The private session verifies the client, daemon, and lookup path; the desktop's PAM integration, which unlocks the login keyring at graphical login, is the documented production path and was not exercised here.

secret-tool command Description
store --label=LABEL ATTR VALUE Read a secret from standard input and store it under the attributes.
lookup ATTR VALUE Print the secret matching the attributes.
clear ATTR VALUE Delete the matching secret.
search ATTR VALUE List matching items without printing their secrets.

Screen locking and keyring unlocking are related but distinct: a locker covers the session and requires authentication to return, while a keyring unlock releases stored secrets. Xfce can use light-locker, and xflock4 is a wrapper that selects an available locker. Both packages are installed on the example machine:

$ dpkg-query -W light-locker
light-locker    1.8.0-3+b1
$ command -v xflock4
/usr/bin/xflock4

A locker can only run inside a graphical session, which is the expected boundary of this capture - started from a text shell it fails before it can lock anything:

$ light-locker --version

** (light-locker:430056): WARNING **: 11:55:41.474: Cannot open display:

Inside a session, the desktop's lock action runs the locker, the screen is covered, and unlocking requires the user's password; loginctl lock-session asks the session's locker to lock and depends on that locker being present. Locking on suspend is set by the desktop's power settings together with the locker's own configuration. On a real workstation, confirm that the locker covers the screen and that the keyring is still usable after unlocking.

Accessibility is also a session-level facility. Orca is a screen reader that uses the AT-SPI2 accessibility bus; BRLTTY and xbrlapi provide braille support. The example machine has Orca and the AT-SPI2 core installed:

$ orca --version
Orca version 48.1, AT-SPI2 version: 2.56.2, Session: tty

Selected output; the command's two libwnck warnings about the absent X11 display are omitted and are expected in a text session. The version line identifies the installed accessibility stack. GNOME and other toolkits expose their accessibility trees only when the toolkit accessibility bridge is enabled, and the setting is per user. Save this script in the workspace as accessibility-test.sh to check and change it:

#!/bin/sh
set -eu
gsettings get org.gnome.desktop.interface toolkit-accessibility
gsettings set org.gnome.desktop.interface toolkit-accessibility true
gsettings get org.gnome.desktop.interface toolkit-accessibility
gsettings set org.gnome.desktop.interface toolkit-accessibility false

It reads the current value, enables the bridge, reads the value again, and sets the value back to false - the original state on this machine. The final line hardcodes that value, so adjust it if the starting value on another machine is different, or the script will change it. Make it executable and run it in a private session bus, where the dconf service starts on demand:

$ chmod +x /home/john/debian-handbook/desktop-baseline/accessibility-test.sh
$ dbus-run-session -- /home/john/debian-handbook/desktop-baseline/accessibility-test.sh
false
true

The two printed lines are the value before and after the change; the final set restores false silently. The setting lives in the user's dconf database, so it affects that user only, and applications that were already running may need to be restarted before they expose their accessibility trees.

Component Package or service Purpose
Secret Service gnome-keyring, libsecret-tools Store and retrieve application secrets.
Screen locker light-locker, xflock4 Cover the session and require authentication.
Screen reader orca, at-spi2-core Read the accessibility tree and announce interface changes.
Braille xbrlapi, brltty Drive a braille display and expose braille input.
Toolkit bridge org.gnome.desktop.interface toolkit-accessibility Make toolkit widgets visible to assistive technologies.

Accessibility settings are not cosmetic. A user who depends on a screen reader or braille display may be unable to log in if the greeter, the keyring prompt, or the locker does not expose an accessible interface, so test those entry points - not only desktop applications - when preparing an accessible workstation.

4.5.4. Desktop Network Controls and Their Configuration Backend

Debian can manage network interfaces with several backends. ifupdown reads /etc/network/interfaces; NetworkManager uses connection profiles and D-Bus; systemd-networkd uses .network and .netdev files. A desktop normally installs NetworkManager, but the installer or an administrator may leave an interface under another backend, which is why a machine can have NetworkManager running while an interface is deliberately unmanaged.

Backend Configuration Typical use How to inspect
ifupdown /etc/network/interfaces and /etc/network/interfaces.d/ Servers, minimal installs, fixed management interfaces ifquery, ip addr, ip route
NetworkManager keyfiles under /etc/NetworkManager/system-connections/ Desktops, Wi-Fi, VPNs, roaming nmcli, nm-connection-editor
systemd-networkd .network and .netdev files under /etc/systemd/network/ Servers and containers with systemd-managed links networkctl, ip addr

The daemon's overall view comes first:

$ nmcli general status
STATE      CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN     METERED
connected  unknown       missing  enabled  missing  enabled  unknown
$ nmcli device status
DEVICE  TYPE      STATE                   CONNECTION
lo      loopback  connected (externally)  lo
eth0    ethernet  unmanaged               --

The management interface eth0 is unmanaged: NetworkManager is not the program that configured its address, because this machine's primary interface is deliberately owned by another backend. That is a working configuration, not a failure, and it is why the desktop's network panel does not offer eth0 for editing.

Warning: The unmanaged interface carries this machine's management address and SSH access. The exercise below deliberately uses a dummy profile instead, so nothing done here touches eth0. Deleting or downing the profile that carries a machine's management address can end an SSH session and leave the machine unreachable; use a secondary interface, a dummy link, or a console recovery path for network experiments.

A dummy connection is a synthetic interface with no hardware behind it, which makes it a safe stand-in for testing NetworkManager itself. Creating the profile with an interface name also creates the dummy link and applies the address immediately:

$ sudo nmcli connection add type dummy ifname ch04dummy con-name ch04-dummy ipv4.method manual ipv4.addresses 198.51.100.10/24
Connection 'ch04-dummy' (45761ec7-5dbd-47df-97e1-bb23d7066af6) successfully added.

The UUID is generated by NetworkManager and differs on every system. NetworkManager can report the profile's configured address directly, and the kernel confirms the address on the link:

$ nmcli -g IP4.ADDRESS connection show ch04-dummy
198.51.100.10/24
$ ip -brief addr show ch04dummy
ch04dummy        UNKNOWN        198.51.100.10/24

The UNKNOWN state is normal for a dummy interface, which has no carrier. The profile is stored as a keyfile under /etc/NetworkManager/system-connections/:

[connection]
id=ch04-dummy
uuid=45761ec7-5dbd-47df-97e1-bb23d7066af6
type=dummy
interface-name=ch04dummy

[dummy]

[ipv4]
address1=198.51.100.10/24
method=manual

[ipv6]
addr-gen-mode=default
method=disabled

[proxy]

The listing is the content of /etc/NetworkManager/system-connections/ch04-dummy.nmconnection. It is normally mode 0600 and owned by root, because profiles can contain Wi-Fi passwords and other secrets; a Wi-Fi profile would add [wifi] and [wifi-security] sections. Editing keyfiles directly requires nmcli connection reload before NetworkManager reads the change.

NetworkManager validates input before accepting it. An invalid address is rejected with a specific message and a nonzero status, and the profile is not changed:

$ sudo nmcli connection modify ch04-dummy ipv4.addresses 198.51.100.999/24
Error: failed to modify ipv4.addresses: invalid IP address: Invalid IPv4 address '198.51.100.999'.

Validation is not a reachability test: a syntactically valid address can still be on the wrong subnet, duplicate another host, or be unroutable, so check routes and connectivity after activation. Remove the test profile:

$ sudo nmcli connection delete ch04-dummy
Connection 'ch04-dummy' (45761ec7-5dbd-47df-97e1-bb23d7066af6) successfully deleted.

Deleting the profile also removes the dummy device it had created, which the address query reports as a missing device with exit status 1:

$ ip -brief addr show ch04dummy
Device "ch04dummy" does not exist.

Confirm that the management path is untouched:

$ ip route
default via 192.168.121.1 dev eth0
192.168.121.0/24 dev eth0 proto kernel scope link src 192.168.121.39
$ ping -c 1 192.168.121.1
PING 192.168.121.1 (192.168.121.1) 56(84) bytes of data.
64 bytes from 192.168.121.1: icmp_seq=1 ttl=64 time=0.205 ms

--- 192.168.121.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.205/0.205/0.205/0.000 ms

The cleanup removed only the dummy profile and its synthetic device; the management address, default route, and SSH service were unchanged.

nmcli form Description
general status Show daemon state, connectivity, and radio availability.
device status Show devices, their state, and the connection that owns them.
connection show List profiles.
connection show NAME Show one profile's settings.
connection add TYPE ... Create a profile.
connection modify NAME PROPERTY VALUE Change one or more profile settings.
connection up NAME / down NAME Activate or deactivate a profile.
connection delete NAME Delete a profile.
-g FIELD Print only the named field, for scripts.

Do not run two managers on the same interface unless the split is intentional. NetworkManager marks an interface unmanaged when its configuration excludes it or another backend owns it, which prevents it from competing for addresses and routes. If a desktop's network panel cannot find an interface, check nmcli device status and the manager configuration before installing another network tool. Chapter 17 covers the backends, wireless configuration, and diagnosis in depth.