Useradd
In Unix-like operating systems, you can add users using various commands depending on the distribution. Here I provided 10 examples of adding users in Unix:
Command Name: /useradd
Description: The useradd command creates a new user account. The login parameter must be a unique string (its length is can be configured by administrators using the chdev command). You cannot use the ALL or default keywords in the user name. The useradd command does not create password information for a user.
Syntax: sudo useradd [option] newuser
Use Case:
1.)Using the useradd command with default options:
useradd username
2.)Adding a user with a specific home directory:
useradd -d /home/username username
3.)Setting the default shell for the user:
useradd -s /bin/bash username
4.)Specifying the user's primary group:
useradd -g groupname username
5.)Specifying the user's primary group:
useradd -g groupname username
6.)Setting the expiry date for the user account:
useradd -e YYYY-MM-DD username
7.)Creating a user and immediately assigning a password:
useradd -p password username
8.)Creating a user and adding them to supplementary groups:
useradd -G group1,group2 username
9.)Adding a comment or description to the user account:
useradd -c "John Doe" username
10.)Creating a system user without login privileges:
useradd -r username
11.)Creating a user with an expiry date and a primary group:
useradd -e YYYY-MM-DD -g groupname username
12.)Creating a user without login privileges and a home directory:
useradd -r -d /home/username username
13.)Creating a user with a primary group and the default bash shell
useradd -g groupname -s /bin/bash ushername
These examples showcase the different options available when adding users in Unix-like systems using commands like useradd. Depending on the specific requirements and system configurations, you can adjust the options accordingly to suit your needs.