Creating User Mohammed on App Server 3 in Stratos Datacenter
Objective
This document outlines the procedure for creating a new user account on App Server 3 (stapp03) in the Stratos Datacenter. The system administration team has specified the following requirements:
- Username: mohammed
- UID: 1403
- Home Directory: /opt/mohammed
- Primary Group: nautilus_admin_users
Environment Details
- Server: stapp03 (App Server 3)
- Access User: banner
- Access Password: BigGr33n
- Sudo Privileges: Required
Implementation Methods
Method 1: One-Line Command Execution
Execute the following command from the jump host to create the user and group with a single command:
echo 'BigGr33n' | ssh banner@stapp03 "sudo -S bash -c 'groupadd nautilus_admin_users 2>/dev/null; useradd -u 1403 -d /opt/mohammed -m -g nautilus_admin_users mohammed 2>/dev/null; id mohammed; groups mohammed; ls -ld /opt/mohammed'"
This command performs the following actions:
- Creates the group nautilus_admin_users if it does not already exist
- Creates the user mohammed with UID 1403, home directory /opt/mohammed, and sets nautilus_admin_users as the primary group
- Displays verification information for the newly created user
Method 2: Heredoc Method
For a more comprehensive output with detailed verification, use the heredoc approach:
ssh banner@stapp03 << 'EOF'
echo 'BigGr33n' | sudo -S bash -c '
echo "Creating group nautilus_admin_users"
groupadd nautilus_admin_users 2>/dev/null || echo "Group already exists"
echo "Creating user mohammed"
useradd -u 1403 -d /opt/mohammed -m -g nautilus_admin_users mohammed 2>/dev/null || echo "User already exists"
echo "Verification Results:"
echo "User Details:"
id mohammed
echo "Home Directory:"
ls -ld /opt/mohammed
echo "Group Membership:"
groups mohammed
echo "User Entry in /etc/passwd:"
grep mohammed /etc/passwd
echo "Group Entry in /etc/group:"
grep nautilus_admin_users /etc/group
'
EOF
Method 3: Interactive Session
For manual execution, connect to the server and perform the following commands:
# Connect to App Server 3
ssh banner@stapp03
# Enter password: BigGr33n
# Switch to root
sudo su -
# Enter password: BigGr33n
# Create the group
groupadd nautilus_admin_users
# Create the user with specified parameters
useradd -u 1403 -d /opt/mohammed -m -g nautilus_admin_users mohammed
# Verify the creation
id mohammed
ls -ld /opt/mohammed
groups mohammed
grep mohammed /etc/passwd
grep nautilus_admin_users /etc/group
# Exit
exit
exit
Command Breakdown
The useradd command uses the following parameters:
-
-u 1403: Sets the user ID to 1403 -
-d /opt/mohammed: Specifies the home directory location -
-m: Creates the home directory if it does not exist -
-g nautilus_admin_users: Sets the primary group -
mohammed: The username
Verification Procedures
After creating the user, verify the configuration using these commands:
# Verify user exists and UID is correct
id mohammed
# Verify home directory exists and ownership
ls -ld /opt/mohammed
# Verify group membership
groups mohammed
# Verify user entry in system files
grep mohammed /etc/passwd
# Verify group exists
getent group nautilus_admin_users
Expected Output
Upon successful execution, the system should display:
uid=1403(mohammed) gid=1404(nautilus_admin_users) groups=1404(nautilus_admin_users)
drwx------ 2 mohammed nautilus_admin_users 4096 Jul 19 10:00 /opt/mohammed
mohammed : nautilus_admin_users
mohammed:x:1403:1404::/opt/mohammed:/bin/bash
nautilus_admin_users:x:1404:mohammed
Alternative Approaches
Manual Home Directory Creation
If the home directory needs to be created separately:
mkdir -p /opt/mohammed
useradd -u 1403 -d /opt/mohammed -g nautilus_admin_users mohammed
chown mohammed:nautilus_admin_users /opt/mohammed
chmod 700 /opt/mohammed
Modifying an Existing User
If the user already exists, update their configuration:
usermod -u 1403 -d /opt/mohammed -g nautilus_admin_users mohammed
mkdir -p /opt/mohammed
chown mohammed:nautilus_admin_users /opt/mohammed
Setting User Shell
To specify a custom shell for the user:
useradd -u 1403 -d /opt/mohammed -m -g nautilus_admin_users -s /bin/bash mohammed
Troubleshooting
User Already Exists
If the user already exists, modify the existing user account:
usermod -u 1403 -d /opt/mohammed -g nautilus_admin_users mohammed
mkdir -p /opt/mohammed
chown mohammed:nautilus_admin_users /opt/mohammed
Group Already Exists
If the group already exists, proceed with user creation:
useradd -u 1403 -d /opt/mohammed -m -g nautilus_admin_users mohammed
Permission Issues
Ensure proper sudo privileges:
sudo su -
# or use sudo with the command
sudo useradd -u 1403 -d /opt/mohammed -m -g nautilus_admin_users mohammed
Invalid UID Error
Verify the UID is valid and not in use:
cut -d: -f3 /etc/passwd | sort -n
Home Directory Not Created
Create and set permissions manually:
mkdir -p /opt/mohammed
chown mohammed:nautilus_admin_users /opt/mohammed
chmod 700 /opt/mohammed
Security Considerations
After creating the user, consider implementing these additional security measures:
Set User Password
passwd mohammed
Configure Password Expiry
chage -E 2027-12-31 mohammed
Set Appropriate Home Directory Permissions
chmod 700 /opt/mohammed
chown -R mohammed:nautilus_admin_users /opt/mohammed
Restrict Shell Access
For service accounts, set a restricted shell:
usermod -s /sbin/nologin mohammed
Automated Script
For repeatable deployments, save this as create_user.sh:
#!/bin/bash
echo "Creating User mohammed on App Server 3"
ssh banner@stapp03 << 'EOF'
echo 'BigGr33n' | sudo -S bash -c '
groupadd nautilus_admin_users 2>/dev/null
useradd -u 1403 -d /opt/mohammed -m -g nautilus_admin_users mohammed 2>/dev/null
echo "Verification Results:"
id mohammed
ls -ld /opt/mohammed
groups mohammed
grep mohammed /etc/passwd
grep nautilus_admin_users /etc/group
'
EOF
Make the script executable and run:
chmod +x create_user.sh
./create_user.sh
Summary
The user mohammed has been successfully created on App Server 3 (stapp03) in the Stratos Datacenter. The configuration includes:
- Username: mohammed
- UID: 1403
- Home Directory: /opt/mohammed
- Primary Group: nautilus_admin_users
- Shell: /bin/bash (default)
The home directory has been created with appropriate ownership and permissions. The user is now ready for use on App Server 3 with all specified requirements satisfied. Verification commands confirm the user exists, the UID is correct, the home directory is properly configured, and the user is a member of the correct group.
Top comments (0)