Use of this command:
'useradd' command is used to add a new user into the system. In other words, it creates a new login account for a different user.
Remember that only the root user can add new users into the system.
You can check who are the existing users in /etc/passwd file
To simply add a user to the system, this command is used:
useradd virat
This command adds the user named virat into the system and you can check whether virat is added or not in the /etc/passwd file.
This is just a basic way of adding users into the system.Now let us explore the various options of useradd command.
But before going to that, let us understand all the fields in /etc/passwd file.
There are 7 fields in /etc/passwd file for every user.
1. Username: Name of the user.
2. Password: This password is not visible. (marked x)
3. UID: User ID
4. GID: The group ID of which the user belongs to.
5. Comment field: Here the user can write anything which he/she wants to. This is optional.
6. User home directory: The user's home directory is shown in this field. By default, the user's home directory will be /home/username.
7. Default shell: This shows the name of the default shell with which user interacts. By default, it is bash shell.
Now that you've known about the fields of /etc/passwd file, let us explore various options of useradd command.
1. useradd -c: To add a comment
2. useradd -d: To set a home directory. If you don't set, the default one will be /home/username
3. useradd -u: Customize UID, set UID of your choice.
4. useradd -g: Add the user to an existing group with that existing group's GID.
5. useradd -G: Add the user to supplementary groups, i.e, other than the default primary group.
6. useradd -e: Add the user with an expiration date. After the specified date, the user is disabled.
7. useradd -s: sets the default shell for the user. If this is not set, the default shell will be bash.
Fun part:
Which command is used to create a user by taking password on the spot?
Post your answer in the comment section if you got it.
Comments
Post a Comment