# loginctl — Manage Sessions and Users with systemd-logind

> Practical guide to loginctl: list, lock and terminate systemd-logind sessions and users, and use linger to keep services running without an active login.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/loginctl/

<!-- PROSE:intro -->
loginctl is your interface to the systemd login manager (`systemd-logind`) and shows you who is currently logged in to your system – across sessions, users and physical seats. You can inspect and lock sessions, terminate stuck logins, and use linger to keep user services running even without an active login. This guide walks you through the commands you actually reach for in everyday administration and troubleshooting, from read-only inspection to the operations that intervene.
<!-- PROSE:intro:end -->

## Sessions

`loginctl list-sessions` — List all active sessions.

```bash
loginctl list-sessions
```

`loginctl session-status <session-id>` — Show detailed status of a session.

```bash
loginctl session-status 3
```

`loginctl show-session <session-id>` — Show properties of a session (machine-readable).

```bash
loginctl show-session 3
```

`loginctl terminate-session <session-id>` — Terminate a specific session (destructive: programs running in the session are killed).

```bash
sudo loginctl terminate-session 3
```

`loginctl lock-session <session-id>` — Lock a session's screen.

```bash
loginctl lock-session 3
```

`loginctl unlock-session <session-id>` — Unlock a session's screen.

```bash
loginctl unlock-session 3
```

## Users

`loginctl list-users` — List all logged-in users.

```bash
loginctl list-users
```

`loginctl user-status <user>` — Show detailed status of a user's sessions.

```bash
loginctl user-status admin
```

`loginctl show-user <user>` — Show properties of a user (machine-readable).

```bash
loginctl show-user admin
```

`loginctl terminate-user <user>` — Terminate all sessions of a user (destructive: unsaved work is lost).

```bash
sudo loginctl terminate-user guest
```

`loginctl kill-user <user>` — Send a signal to all processes of a user (destructive: kills running processes).

```bash
sudo loginctl kill-user guest
```

## Linger

`loginctl enable-linger <user>` — Enable linger: user services run even without an active login.

```bash
sudo loginctl enable-linger deploy
```

`loginctl disable-linger <user>` — Disable linger: user services stop when the user logs out.

```bash
sudo loginctl disable-linger deploy
```

`loginctl show-user <user> -p Linger` — Check if linger is enabled for a user.

```bash
loginctl show-user deploy -p Linger
```

## Seats

`loginctl list-seats` — List all seats (physical workstations).

```bash
loginctl list-seats
```

`loginctl seat-status <seat>` — Show status of a seat.

```bash
loginctl seat-status seat0
```

`loginctl show-seat <seat>` — Show properties of a seat.

```bash
loginctl show-seat seat0
```

<!-- PROSE:outro -->
## Conclusion

loginctl is your window into systemd's session management: `list-sessions`, `list-users` and `session-status` safely show you who is logged in and what is running – ideal for troubleshooting. `enable-linger` is especially useful: only with it do services started via `systemctl --user` (a deploy worker or a background job, say) keep running once nobody is logged in anymore. Be careful with the operations that intervene: `terminate-session`, `terminate-user` and `kill-session`/`kill-user` end running sessions and processes immediately – any unsaved work of the affected users is lost. These commands need `sudo`, and loginctl only works on systemd-based systems.

## Further Reading

- [Arch Wiki: systemd/User](https://wiki.archlinux.org/title/Systemd/User) – user services, linger and the user instance of systemd
- [systemd-logind.service (man page)](https://www.freedesktop.org/software/systemd/man/latest/systemd-logind.service.html) – the official reference for the login manager loginctl talks to
<!-- PROSE:outro:end -->

## Related Commands

- [systemctl](https://www.jpkc.com/db/en/cheatsheets/shell-system/systemctl/) – control systemd services and units (including `--user` services)
- [journalctl](https://www.jpkc.com/db/en/cheatsheets/shell-system/journalctl/) – query the systemd journal and inspect session logs
- [su](https://www.jpkc.com/db/en/cheatsheets/shell-system/su/) – switch users and run commands as another user

