Useradd command on Linux (create user)
The useradd command on Linux creates user accounts on the system. Its only mandatory parameter is the user’s login.
If no options are provided, the useradd command will use the variables configured in the /etc/default/useradd file. The content of this file may vary according to each distribution:
If any option is used when creating a user account with useradd, it will be used instead of the corresponding variable in /etc/default/useradd. The information in this file will only be completely ignored if all the corresponding options are used when creating the user.
The most common options are:
- -c “username”: This option saves the name of the account owner or any other important notes and comments to the passwd file. It is an alphanumeric field and must be enclosed in double quotes;
- -d home_directory: This option provides the full path to the user’s home directory;
- -m: Creates the home directory provided in the “-d” option with the files and structure defined in the /etc/ configuration skel;
- -g group_number: This option provides the user’s default account group;
- -s shell: This option must provide the full shell path used by the account. For example /bin/bash, /bin/tcsh, /bin/false, etc.
The account password must be configured after creating the account with the passwd command.
Examples:
In the example, useradd creates the user Uira with the home directory /home/uira with the structure defined in /etc/skel, with the name “Uira Ribeiro” in the comments, with the shell /bin/bash and the GID group 100.
A user can be created simply with the command below, informing only the login. In this case the /etc/default/useradd options were used to configure the user account
Once the user account is created, the data can be changed manually by editing the /etc/passwd file, or using the usermod command.
Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it?
Share