Ubuntu – Create system user without login
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
To create a system user without login on Ubuntu (i.e., a user that cannot log in interactively, typically used for services), use the adduser command with the --system and --no-create-home options, or useradd with appropriate flags.
Recommended Method (using adduser – interactive and safer):
sudo adduser --system --no-create-home --group myserviceuser
--system: Creates a system user (UID < 1000, no password, no home by default).--no-create-home: Prevents creating a home directory.--group: Creates a primary group with the same name (optional but common for system users).- No password is set → cannot log in.
Alternative (using useradd – non-interactive):
sudo useradd -r -s /usr/sbin/nologin -M myserviceuser
-r: System user.-s /usr/sbin/nologin: Sets shell tonologin(prevents interactive login).-M: Do not create home directory.
Note: On Ubuntu,
/usr/sbin/nologinis preferred over/bin/falsebecause it displays a polite message when login is attempted.
Verify the user was created:
id myserviceuser
getent passwd myserviceuser
Example output:
myserviceuser:x:116:122::/nonexistent:/usr/sbin/nologin
Optional: Disable password entirely (extra security)
sudo passwd -l myserviceuser
This locks the password field.
Use Case Example (e.g., for a service like Nginx or a custom daemon):
sudo adduser --system --no-create-home --group nginx
Then run your service as this user:
sudo -u nginx your-command
Summary:
Use sudo adduser --system --no-create-home --group <username> for a clean, login-disabled system user on Ubuntu.

