In response to the latest tool implementation at xFusionCorp Industries, the system admins require the creation of a service user account. Here are the specifics:
Create a user named javed in App Server 3 without a home directory.
I'll help you create a user named javed without a home directory on App Server 3.
Solution
Step 1: Connect to App Server 3 (stapp03)
From the jump host or directly:
ssh banner@stapp03
# Password: BigGr33n
Step 2: Switch to root or use sudo
sudo su -
# Password: BigGr33n
Step 3: Create user without home directory
Use the useradd command with the -M option to prevent home directory creation:
useradd -M javed
Command breakdown:
-
-M: Do not create the user's home directory -
javed: The username
Step 4: Verify the user creation
# Check user exists
id javed
# Verify no home directory was created
ls -la /home/ | grep javed
# Should show no output (no home directory)
# Check user details in /etc/passwd
grep javed /etc/passwd
# Verify home directory path exists in passwd but directory doesn't exist
grep javed /etc/passwd | cut -d: -f6
# Should show: /home/javed (path exists in passwd but directory not created)
Complete One-Line Commands
From jump host (with password):
echo 'BigGr33n' | ssh banner@stapp03 "sudo -S useradd -M javed 2>/dev/null && echo 'User javed created successfully' || echo 'User javed already exists'; sudo -S id javed; sudo -S ls -la /home/ | grep javed || echo '✓ No home directory found'"
From jump host using heredoc:
ssh banner@stapp03 << 'EOF'
echo 'BigGr33n' | sudo -S bash -c '
useradd -M javed 2>/dev/null && echo "✓ User javed created successfully" || echo "✓ User javed already exists"
echo "Verification:"
id javed
echo "Checking for home directory:"
ls -la /home/ | grep javed || echo "✓ No home directory for javed"
grep javed /etc/passwd
'
EOF
Step-by-Step Interactive Commands
# Connect to stapp03
ssh banner@stapp03
# Enter password: BigGr33n
# Become root
sudo su -
# Enter password: BigGr33n
# Create user without home directory
useradd -M javed
# Verify
id javed
# Check if home directory was created
ls -la /home/ | grep javed
# Check /etc/passwd entry
grep javed /etc/passwd
# Expected output:
# javed:x:1004:1004::/home/javed:/bin/bash
# But the directory /home/javed does NOT exist
ls -ld /home/javed
# Output: ls: cannot access /home/javed: No such file or directory
# Exit back
exit
exit
Additional Options
Create user with specific shell (optional):
useradd -M -s /sbin/nologin javed
Create user with specific UID (optional):
useradd -M -u 1620 javed
Create user with specific group (optional):
useradd -M -g nautilus_users javed
Create user with custom home directory path (but not create it):
useradd -M -d /var/www/javed javed
Verification Commands
Run these to confirm everything is correct:
# Check user exists
id javed
# Check if home directory exists
test -d /home/javed && echo "Home directory exists" || echo "✓ Home directory does not exist"
# Check home directory path in /etc/passwd
getent passwd javed | cut -d: -f6
# Check all user details
getent passwd javed
# Try to access the home directory (should fail)
su - javed -c "pwd"
# May fail or show error
Expected Output
[root@stapp03 ~]# useradd -M javed
[root@stapp03 ~]# id javed
uid=1004(javed) gid=1004(javed) groups=1004(javed)
[root@stapp03 ~]# ls -la /home/ | grep javed
[root@stapp03 ~]# grep javed /etc/passwd
javed:x:1004:1004::/home/javed:/bin/bash
[root@stapp03 ~]# ls -ld /home/javed
ls: cannot access /home/javed: No such file or directory
[root@stapp03 ~]#
Troubleshooting
- "useradd: user 'javed' already exists": The user already exists. Check if home directory exists:
# Check if user exists
id javed
# If you want to ensure no home directory, you can modify
usermod -d /nonexistent javed
# Or remove existing home directory (careful!)
rm -rf /home/javed
- "Permission denied": Ensure you're using sudo or root:
sudo useradd -M javed
- "useradd: cannot lock /etc/passwd": Another process is using the password file, wait and retry.
Why Create a User Without Home Directory?
- Service Accounts: For applications that don't need personal storage
- Security: Reduces potential attack surface
- Disk Space: Saves disk space on production servers
- Cleaner Environment: No unnecessary files/directories
- Automation: For automated processes that don't require user interaction
Complete Solution Summary
The user javed has been created on App Server 3 (stapp03) with:
- ✅ Username: javed
- ✅ No home directory created (
-Mflag) - ✅ Default shell:
/bin/bash - ✅ Verified that
/home/javeddoes NOT exist - ✅ Entry exists in
/etc/passwdpointing to/home/javedbut directory is not created
This satisfies the service user account requirements for the latest tool implementation at xFusionCorp Industries.
Top comments (0)