If it's not installed, log in to an account with appropriate permissions for creating users. To force the creation of a home directory, use the following command:. If you want the user to have a home folder in a different place than the default, use the -d switch. The above command creates a folder called test for user test under the root folder. Within the -m switch, the folder may not be created. At the bottom of the file, add the following line:. After you create a user with a home folder, change the user's password.
To set a user's password, use the following command:. The passwd command allows you to set the test user's password. You will be prompted for the password you wish to use. Test your new user's account by typing the following into a terminal window:. The above command switches user to the test account and, assuming you created a home folder, you will be placed in the home folder for that user. If you work in an office and a new contractor is going to be at your office for a short period of time, set an expiry date on their user account.
Similarly, if you have family coming to stay, create a user account for that family member that expires after they depart. To set an expiry date when creating a user, use the following command:. When a new user joins your company, assign specific groups for that user so that they have access to the same files and folders as other members of their team.
For example, John is joining as an accountant. The following command would add john to the accounts group. There are some key settings in this file. The login. The -f option is used to specify the number of days after a password expires until the account is permanently disabled. A value of 0 disables the account as soon as the password has expired. The default value is -1, which disables this feature. The name or number of the new user's initial login group can be specified by placing it after the -g option.
The group name must already exist, and a group number must refer to an already existing group. The -G option is used to provide a list of additional groups into which the user is also included. Each group name or number is separated from the next by a comma, with no intervening spaces.
The groups are subject to the same restrictions as the group specified with the -g option. The -m option, which does not accept any arguments i.
The -M option is used to create a new user without creating any home directory for that user. When such a user logs into a system that has just booted up, its login directory will likely be the root directory; when such a user logs into a system using the su command, its login directory will be the current directory of the previous user.
On Red Hat systems a new group having the same name as the user being added to the system will be created by default. The above entry contains a set of seven colon-separated fields, each field has its own meaning. You can see the user home directory and other user-related information like user id, group id, shell, and comments.
By default, whenever we create a new user account in Linux , it assigns userid , , , and so on…. We can create users with specific group IDs as well with the -g option. Each group name is separated by a comma, with no intervening spaces.
In such a situation, when a user logs into a system that has just restarted, its home directory will be root. This is helpful for creating temporary accounts for a specific period of time. A value of 0 inactive the user account as soon as the password has expired. By default, the password expiry value set to -1 means never expire. Here in this example, we will set an account password expiry date i.
The comment can be added as a single line without any spaces. Sometimes, we add users who have nothing to do with the login shell or sometimes we require to assign different shells to our users. The following command is very different than the other commands explained above. TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web.
Millions of people visit TecMint! If you like what you are reading, please consider buying us a coffee or 2 as a token of appreciation. We are thankful for your never ending support.
Depends on the distro. How to create users using useradd command in Linux? Home How to create users using useradd command in Linux? By: Baljit Singh Saini commands. PPT on useradd command. Video on useradd command.
0コメント