User Management Task: Creating and Removing Users Securely¶
Goal¶
Ensure users are added or removed in a consistent, auditable, and secure way.
Creating Users¶
useradd -m -s /bin/bash -G wheel username
passwd username
Add SSH Key¶
mkdir -p /home/username/.ssh
echo "ssh-rsa AAAA..." > /home/username/.ssh/authorized_keys
chown -R username:username /home/username/.ssh
chmod 700 /home/username/.ssh
chmod 600 /home/username/.ssh/authorized_keys
Removing Users¶
userdel -r username
- Check crontabs:
crontab -u username -l - Remove sudo if applicable
Best Practices¶
- Disable before deleting (
usermod -L) - Backup home directory if needed
Tools¶
useradd,passwd,userdel,usermod,sudo