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. Please give and explain several examples of each to enhance his understanding. Assume that he typically runs commands using "sudo".
Certainly! Christian, as a RHEL Sysadmin at Google, can benefit from understanding the similarities and differences between the
adduser commands. Here are several examples of each command, along with explanations:
useraddcommand is used to create a new user account on the system.
Example 1: Create a user with a specified home directory and login shell:
sudo useradd -d /home/john -s /bin/bash john
This command creates a user account named "john" with the home directory set to "/home/john" and the default shell set to "/bin/bash".
Example 2: Create a user with a specific UID and GID:
sudo useradd -u 1001 -g 1001 jenny
This command creates a user account named "jenny" with the user ID (UID) set to 1001 and the primary group ID (GID) set to 1001.
addusercommand is a higher-level utility that interacts with
useraddto simplify user account creation and provide a more interactive experience.
Example 1: Create a user with default options:
sudo adduser john
This command launches an interactive prompt where Christian can provide additional details like the user's full name, password, and other optional details.
Example 2: Create a user and add to supplementary groups:
sudo adduser jenny developers
This command creates a user account named "jenny" and adds them to the supplementary group "developers" in addition to the default primary group.
- Both commands are used for creating user accounts.
- They require elevated privileges and are typically executed with
- They create an entry in the system's user database (/etc/passwd and /etc/shadow files).
useraddis a lower-level command with more options and flexibility, while
adduserprovides a simplified and interactive interface.
adduserautomatically creates the home directory and sets up some default configurations, whereas
useraddrequires manual specification of these options.
adduseradds the user to additional supplementary groups by default, while
useraddonly adds the user to the primary group.
By understanding these examples and the differences between the
adduser commands, Christian can effectively choose the appropriate command based on his specific requirements and preferences as a RHEL Sysadmin at Google.