How to Completely Disable the ‘systemd-user-sessions’ Service in Ubuntu Server

In Ubuntu Server, systemd-user-sessions.service is a specific initialization daemon designed to manage user logins during the boot and shutdown phases. Its primary function is to prevent non-root users from logging into the system while the OS is still initializing services (by creating /run/nologin) and then removing that block once the multi-user target is fully reached. During shutdown, it blocks new logins and terminates active user sessions gracefully. While critical for multi-user desktop environments or shared jump-hosts, this service is entirely unnecessary on dedicated, single-purpose appliances, immutable infrastructure nodes, or strict servers where only root (or a specific administrative account via SSH keys) is permitted to log in at any time.

This guide explains how to completely disable the systemd-user-sessions service in Ubuntu Server, ensuring the init system does not waste cycles managing generic user login states during state transitions.

Stop and Mask the Systemd-User-Sessions Service

Because this service is tightly integrated into the boot sequence and triggered by various targets, simply disabling it is insufficient to prevent it from being pulled in as a dependency. We must explicitly mask it.

  1. Log into your Ubuntu Server via SSH using an account with sudo privileges.
  2. First, disable the service to remove its symlinks from the multi-user boot target:
    sudo systemctl disable systemd-user-sessions.service
  3. Next, explicitly mask the service. This links the unit file to /dev/null, creating an absolute block against it starting, regardless of what other systemd targets request it:
    sudo systemctl mask systemd-user-sessions.service

Verify the Service Lockdown

By masking systemd-user-sessions.service, you have instructed the init system to ignore the management of /run/nologin during boot transitions. The server assumes that authentication daemons (like SSH) will manage access independently.

To verify the lockdown is successful, run the following command to check the status of the service:

systemctl status systemd-user-sessions.service

The output will clearly state that the service is masked. If you attempt to start the service manually using sudo systemctl start systemd-user-sessions.service, systemd will return a fatal error, confirming that the unit is blocked. Your server boot sequence is now slightly leaner, bypassing user session management logic entirely.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.