Create a user in Ubuntu

Source: Internet
Author: User

Linux is a multi-user multi-task time-sharing operating system. any user who wants to use system resources must first apply for an account from the system administrator and then enter the system as the account. User Accounts can help system administrators track users who use the system and control their access to system resources. They can also help users organize files and provide security protection for users. Each account number has a unique user name and password. After you enter the correct user name and password during logon, you can access the system and your home directory.

To manage user accounts, you must do the following:
· Add, delete, and modify user accounts.
· User password management.
· User group management.

I. User Account Management in Linux

The management of user accounts mainly involves adding, modifying, and deleting user accounts.
To add a user account is to create a new account in the system, and allocate resources such as user numbers, user groups, home directories, and logon shells to the new account. The newly added account is locked and cannot be used.

1. Add a new user account and use the useradd command. The syntax is as follows:

Code:
Useradd option Username
The options are described as follows:

Code:
-C comment specifies an annotation description.
-D directory specifies the user's main directory. If this directory does not exist, you can use the-M option to create a main directory.
-G User Group specifies the user group to which the user belongs.
-G user group, which specifies the additional group to which the user belongs.
The-s shell file specifies the user's logon shell.
-U user number specifies the user number of a user. If the-O option is available at the same time, the user ID of another user can be used again.

User name specifies the login name of the new account.

Example 1:
Code:
# Useradd-D/usr/SAM-m Sam
This command creates a user sam,
The-D and-m options are used to generate a main directory/usr/Sam for the logon SAM (/usr is the parent directory of the default user main directory ).

Example 2:
Code:
# Useradd-S/bin/sh-G group-g adm, root gem
This command creates a new user gem. the user's logon shell is/bin/sh, which belongs to the group user group and also to the ADM and root user groups. The group user group is the main group.

A new group may be created here: # groupadd group and groupadd Adm
Adding a user account adds a record to a new user in the/etc/passwd file and updates other system files, such as/etc/shadow and/etc/group.
Linux provides the integrated system management tool userconf, which can be used to manage user accounts in a unified manner.

2. delete an account

If a user's account is no longer in use, it can be deleted from the system. To delete a user account, you must delete the user record in system files such as/etc/passwd. If necessary, delete the user's home directory. Delete an existing user account and use the userdel command. The format is as follows:

Code:
Userdel option Username

The commonly used option is-R, which is used to delete the user's home directory together.
For example:

Code:
# Userdel Sam

This command deletes the records of the user Sam in the System File (mainly/etc/passwd,/etc/shadow,/etc/group), and deletes the user's home directory.

3. Modify an account

Modifying a user account is to change the user's attributes, such as the user ID, main directory, user group, and logon shell.
Use the usermod command to modify existing user information. The format is as follows:

Code:
Usermod option Username

Common options include-C,-D,-M,-G,-G,-S,-u, and-o. These options have the same meaning as those in the useradd command, you can specify a new resource value for the user. In addition, some systems can use the following options:

Code:
-L New User Name

This option specifies a new account, changing the original user name to the new user name.
For example:
Code:
# Usermod-S/bin/KSh-D/home/Z-G developer Sam
This command changes the logon shell of user Sam to KSh, the main directory to/home/Z, and the user group to developer.

4. User Password Management

An important part of user management is the management of user passwords. A user account has no password when it was created, but is locked by the system and cannot be used. It can only be used after a password is specified, even if it is null.
The shell command used to specify and modify the user password is passwd. Super Users can specify passwords for themselves and other users. Common users can only use them to modify their own passwords. Command Format:
Code:

Passwd option User Name
Available options:

Code:
-L the password is disabled.
-U password unlock.
-D indicates that the account has no password.
-F forces the user to change the password upon next login.
If the default user name is used, modify the password of the current user.

For example, if the current user is Sam, the following command modifies the user's own password:

Code:
$ Passwd
Old password :******
New Password :*******
Re-enter new password :*******

If you are a super user, you can specify the password of any user in the following form:

Code:
# Passwd Sam
New Password :*******
Re-enter new password :*******

When a common user modifies his or her own password, the passwd command First asks for the original password and then asks the user to enter the new password twice. If the two passwords are the same, the original password is not required when the superuser specifies a password for the user.

For the sake of system security, you should select a complicated password. For example, you 'd better use an 8-bit long password, which contains uppercase letters, lowercase letters, and numbers, it should be different from the name and birthday.

When you specify a blank password, run the following commands:

Code:
# Passwd-D Sam


This command deletes the password of the user Sam, so that the system will not ask for the password during the next logon.

The passwd command can also use the-l (LOCK) option to lock a user so that the user cannot log on. For example:

Code:
# Passwd-l Sam


Create a user in Linux (2)

2. User Group Management in Linux

Each user has a user group. The system can centrally manage all users in a user group. Different Linux systems have different user groups. For example, a user in Linux belongs to a user group with the same name as a user group, which is created at the same time.
User Group management involves adding, deleting, and modifying user groups. The addition, deletion, and modification of a group are actually updates to the/etc/group file.

1. Add a new user group to use the groupadd command. The format is as follows:

Code:
Groupadd option User Group

You can use the following options:
Code:
-G gid specifies the group ID (GID) of the new user group ).
-O is generally used together with the-G option, indicating that the GID of the new user group can be the same as the GID of the existing user group in the system.

Example 1:

Code:
# Groupadd group1

This command adds a new group group1 to the system. The Group ID number of the new group is added with 1 on the basis of the current largest group ID number.

Example 2:

Code:
# Groupadd-G 101 group2

This command adds a new group group2 to the system and specifies that the Group ID of the new group is 101.

2. to delete an existing user group, run the groupdel command in the following format:

Code:
Groupdel User Group

For example:

Code:
# Groupdel group1

This command deletes group group1.

3. Run The groupmod command to modify the attributes of a user group. The syntax is as follows:

Code:
Groupmod option User Group

Common options include:
Code:
-G gid: specify a new group ID for the user group.
-O and-G options are used at the same time. The new gid of a user group can be the same as the GID of an existing user group in the system.
-N new user group: Change the user group name to a new name.

Example 1:

Code:
# Groupmod-G 102 group2

This command changes the group ID of group group2 to 102.

Example 2:

Code:
# Groupmod-G 10000-N Group3 group2

This command changes the ID of group group2 to 10000 and the group name to group3.

4. If a user belongs to multiple user groups at the same time, the user can switch between user groups to have permissions for other user groups. After logging on, you can use the newgrp command to switch to another user group. The parameter of this command is the target user group. For example:

Code:
$ Newgrp Root

This command switches the current user to the root user group, provided that the root user group is indeed the user's main group or additional group. Similar to user account management, user group management can also be completed through integrated system management tools.

Allows common users in Linux to have superuser Permissions

1. Enter the superuser mode. Enter "Su". The system will ask you to enter the superuser password and enter the password to enter the superuser mode.

2. Add the write permission for the file.

chmod u+w /etc/sudoers

3. Edit the/etc/sudoers file. Enter the command "Vim/etc/sudoers" and find this line: "root all = (all) All". Add "XXX all = (all) all "(here XXX is the user name to be changed), and then save

ali ALL=(ALL) ALL
U indicates the file owner.
+ W add writable permissions
U + X indicates that only the current user has the write permission.

4. revoke the write permission on the file.

chmod u-w /etc/sudoers

Create a user in Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.