Centos command for creating and modifying users and passwords

Source: Internet
Author: User

Create a user in linux
1. Add an ftp user
Useradd ftpname-d/home/ftp
Passwd ftppwd
Perform the following operations with the root permission:
Service vsftpd start the FTP service provided by Linux
2. Add a common user
Useradd nagios-d/usr/local/nagios
Chown nagios. nagios/usr/local/nagios
Switch the user to a nagios user and add the access user for nagios:
Su nagios
Htpasswd-c/usr/local/nagios/etc/htpasswd. users nagiosadmin
The system will prompt you to enter the password twice, for example, entering nagios twice.
Note: This is the first time a user is created. The "-c" option is required to create a file for storing the user name and password. The "-c" option is not used when the user is added or the password is changed.

Use the useradd command to add a new user account. The syntax is as follows:

Useradd option Username

The options are described as follows:

-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.

For example:

# 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 login sam (/usr is the parent directory of the default user main directory ).

# 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.

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. The contents of these files will be detailed later.

Linux provides the integrated system management tool userconf, which can be used to manage user accounts in a unified manner.

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:

Userdel option Username

The commonly used option is-r, which is used to delete the user's home directory together.

For example:

# 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.

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:

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:

-L New User Name

This option specifies a new account, changing the original user name to the new user name.

For example:

# 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.

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:

Passwd option User Name

Available options:

-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:

$ 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:

# 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:

# 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:

# Passwd-l sam

Related Article

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.