Introduction
The useradd
command is a fundamental tool in Linux for creating and managing user accounts. This guide will walk you through the various options and use cases for this essential command.
Basic Syntax
useradd [options] username
Creating a Basic User Account
To create a new user account:
sudo useradd john
Setting User Password
After creating a user, set their password:
sudo passwd john
Specifying User and Group IDs
To create a user with specific UID and GID:
sudo useradd -u 1005 -g 1005 sarah
Creating Home Directory
To create a user with a home directory:
sudo useradd -m -d /home/alice alice
Assigning Login Shell
To specify a login shell for the user:
sudo useradd -s /bin/bash bob
Adding User Information
To add user details like full name:
sudo useradd -c "John Doe" john
Creating System User Accounts
To create a system user account:
sudo useradd -r -s /bin/false systemuser
Adding Users to Groups
To add a user to multiple groups:
sudo useradd -G wheel,docker,developers jane
Conclusion
The useradd
command is a powerful tool for Linux user management. With these options, you can create and configure user accounts to meet your specific requirements.