Task: Create a user named 'ravi' with a non-interactive shell on app Server 1
ssh tony@172.16.238.10
sudo useradd -s /bin/nologin ravi
Breakdown:useradd
<- Command to create a new user-s /bin/nologin
<- assigns a non-interative shell (prevents login)ravi
<- the username we are creating
Optional:
If /sbin/nologin
doesn't exist on your system, you can use /usr/sbin/nologin
or /bin/false
instead.
Why use /sbin/nologin
?
It prevents the user from opening a terminal session or executing shell commands. For example if the user tries to login via SSH or TTY the system will immediately end the session or display a message.
Common Use Cases:
- System users like www-data, nginx, mysql that run background services but shouldn't log in.
- Users that need limited access, for example file upload via ftp but no shell access.
Shell Path | Allows Login? | Purpose |
---|---|---|
/bin/bash | Yes | Full shell access |
/sbin/nologin | No | Blocks login and shows message |
/bin/false | No | Blocks login silently |