adduser

Christian is studying to be a RHEL Sysadmin. Please give and explain 5 examples to help him to master the adduser command.

Certainly! The adduser command is commonly used to create new user accounts on Unix-like systems, including Red Hat Enterprise Linux (RHEL). Here are five examples to help Christian master the usage of the adduser command, along with explanations for each:

1. Basic User Creation:

sudo adduser john

Explanation: This command creates a new user named "john" using default settings. The user's home directory will be created in /home/john, and they will belong to their own group with the same name ("john").

2. Specifying User's Home Directory:

sudo adduser sarah --home /data/users/sarah

Explanation: This command creates a new user named "sarah" and specifies a custom home directory at /data/users/sarah. This is useful when you want to store user data in a specific location.

3. Setting User's Shell:

sudo adduser robert --shell /bin/bash

Explanation: This command creates a new user named "robert" and sets their default shell to /bin/bash. The default shell defines the command interpreter used when the user logs in.

4. Adding User to Supplementary Groups:

sudo adduser anna --ingroup developers --ingroup sudo

Explanation: This command creates a new user named "anna" and adds her to the "developers" group as well as the "sudo" group. Users can belong to multiple supplementary groups, granting them access to various resources.

5. Setting User Expiry Date:

sudo adduser michael --expiredate 2023-12-31

Explanation: This command creates a new user named "michael" and sets an expiry date for the account on December 31, 2023. After this date, the user won't be able to log in unless the expiry date is extended.

Remember, the adduser command might have slight variations in its behavior depending on the specific Linux distribution. In some systems, you might find the useradd command used instead, which serves a similar purpose. Always refer to the manual pages (man adduser or man useradd) for detailed information and options relevant to your specific system.

You should also read:

useradd versus adduser

Christian is a RHEL Sysadmin at Google. He wants to master the similarities and differences between the useradd command and the adduser command.