Use the useradd command to add a new user (
man useradd):
The command
useradd
affects two files "/etc/passwd" and "/etc/group".
Here's how data is structured in these files:
- /etc/passwd
Where:
-
mtitek
: user name.
-
x
: Placeholder for password. The password is obtained from the "/etc/shadow" file.
-
1000
: User ID.
-
1000
: Group ID.
-
mtitek
: Comment.
-
/home/mtitek
: Home directory.
-
/bin/bash
: User shell.
- /etc/group
Where:
-
mtitek
: group name.
-
x
: Placeholder for password information. The password is obtained from the "/etc/gshadow" file.
-
1000
: Group ID.
-
mtitek
: Commas separated list of users that belong to the group.
Examples:
-
Create a user named "mtitek1" with a default group named "mtitek1".
-
Create a user named "mtitek1" with a default group named "mtitek1".
+ create the home directory "/home/mtitek1".
+ set the "/bin/bash" as the default shell for the user.
-
Create a user named "mtitek1" with a default group named "mtitek1".
+ create the home directory "/home/mtitek1".
+ assign the user to group "group1" and "group2".
+ set the "/bin/bash" as the default shell for the user.
-
Create a user named "mtitek1" with a default group named "mtitek1".
+ set the base home directory to "/mtitek1_home_dir".
+ create the base home directory "/mtitek1_home_dir".
-
Create a user named "mtitek1" with a default group named "mtitek1".
+ set the base directory to "/user_base_dir".
+ create the base home directory "/user_base_dir/mtitek1".