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 useradd
and adduser
commands. Here are several examples of each command, along with explanations:
useradd
command: Theuseradd
command 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.
adduser
command: Theadduser
command is a higher-level utility that interacts withuseradd
to 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.
Similarities:
- Both commands are used for creating user accounts.
- They require elevated privileges and are typically executed with
sudo
. - They create an entry in the system's user database (/etc/passwd and /etc/shadow files).
Differences:
useradd
is a lower-level command with more options and flexibility, whileadduser
provides a simplified and interactive interface.adduser
automatically creates the home directory and sets up some default configurations, whereasuseradd
requires manual specification of these options.adduser
adds the user to additional supplementary groups by default, whileuseradd
only adds the user to the primary group.
By understanding these examples and the differences between the useradd
and adduser
commands, Christian can effectively choose the appropriate command based on his specific requirements and preferences as a RHEL Sysadmin at Google.