To accommodate the backup agent tool's specifications, the system admin team at xFusionCorp Industries requires the creation of a user with a non-interactive shell. Here's your task:
Create a user named john with a non-interactive shell on App Server 1.
Solution
Step 1: Connect to App Server 1 (stapp01)
From the jump host or directly:
ssh tony@stapp01
# Password: Ir0nM@n
Step 2: Switch to root or use sudo
sudo su -
# Password: Ir0nM@n
Step 3: Create user with non-interactive shell
Use the useradd command with the -s option to specify the shell:
useradd -s /sbin/nologin john
Alternative shells for non-interactive users:
-
/sbin/nologin- Most common (disallows login completely) -
/bin/false- Another option that returns false immediately -
/usr/sbin/nologin- Similar to /sbin/nologin
Step 4: Verify the user creation
# Check user details
id john
# Verify the shell is set correctly
grep john /etc/passwd
# Check that user cannot login interactively
su - john
# Should show: This account is currently not available.
Complete One-Line Commands
From jump host (with password):
echo 'Ir0nM@n' | ssh tony@stapp01 "sudo -S useradd -s /sbin/nologin john 2>/dev/null && echo 'User john created successfully' || echo 'User john already exists'; sudo -S grep john /etc/passwd"
From jump host using heredoc:
ssh tony@stapp01 << 'EOF'
echo 'Ir0nM@n' | sudo -S bash -c '
useradd -s /sbin/nologin john 2>/dev/null && echo "✓ User john created successfully" || echo "✓ User john already exists"
echo "Verification:"
grep john /etc/passwd
'
EOF
Step-by-Step Interactive Commands
# Connect to stapp01
ssh tony@stapp01
# Enter password: Ir0nM@n
# Become root
sudo su -
# Enter password: Ir0nM@n
# Create user with non-interactive shell
useradd -s /sbin/nologin john
# Verify
grep john /etc/passwd
# Expected output:
# john:x:[UID]:[GID]::/home/john:/sbin/nologin
# Test the shell (should fail)
su - john
# Output: This account is currently not available.
# Exit back
exit
exit
Additional Options
Create user with specific home directory (optional):
useradd -s /sbin/nologin -d /var/www/john john
Create user with specific UID (optional):
useradd -s /sbin/nologin -u 1615 john
Create user without home directory:
useradd -s /sbin/nologin -M john
Verification Commands
Run these to confirm everything is correct:
# Check user exists
id john
# Check shell in /etc/passwd
grep john /etc/passwd | cut -d: -f7
# Should output: /sbin/nologin
# Check if shell is non-interactive
getent passwd john | awk -F: '{print $7}'
# Should output: /sbin/nologin
# Verify user can't login
su - john -c "echo test"
# Should fail or return nothing
Expected Output
[root@stapp01 ~]# useradd -s /sbin/nologin john
[root@stapp01 ~]# grep john /etc/passwd
john:x:1003:1003::/home/john:/sbin/nologin
[root@stapp01 ~]# su - john
This account is currently not available.
[root@stapp01 ~]#
Troubleshooting
- "useradd: user 'john' already exists": The user already exists, but we can modify their shell:
usermod -s /sbin/nologin john
- "Permission denied": Ensure you're using sudo or root:
sudo useradd -s /sbin/nologin john
- "useradd: cannot lock /etc/passwd": Another process is using the password file, wait and retry.
Why Non-Interactive Shell?
- Security: Prevents the user from logging in interactively
- Service Accounts: Ideal for backup agents, daemons, and automation tools
- SFTP/SCP Only: Can be used with SSH for file transfers only
- Application Specific: Good for users that only need to run specific commands
Complete Solution Summary
The user john has been created on App Server 1 (stapp01) with:
- ✅ Username: john
- ✅ Non-interactive shell:
/sbin/nologin - ✅ Home directory:
/home/john(default) - ✅ Verified that interactive login is disabled
This satisfies the backup agent tool's requirement for a user with a non-interactive shell.
Top comments (0)