How to modify the user name in Linux

Source: Internet
Author: User
Article Title: how to change the user name in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

The user name entered during system installation may not be taken into consideration. If I think this user name is not very good, can I modify it without affecting any operation? Of course, the answer is yes.

Here I will not elaborate on the principle. The specific operation method is as follows:

1. single Mode is recommended (for example, RecoveryMode in ubuntu is used as the root user to log on to the system.

Of course, this is not necessary. If you have two or more users and do not need to change the user, you can obtain the root permission. Is it a bit messy? Because I was changing the two usernames, both of which have the root permission and can be operated in turn. However, it is not as convenient as simply using the root identity.

2. Modify the user name, user group, and home directory in the/etc/passwd file;

3. Modify the username and user group in the/etc/group file, and rewrite/etc/gshadow;

4. Modify the username in the/etc/shadow file. If this parameter is not changed, you cannot log on to the system;

5. Modify/home/olduser to/home/newuser. Make sure to modify the user and user group to which the user belongs. Add a-R to chown, which is critical;

These five steps are indispensable, and Operation errors may lead to the inability to log on to the system. You can complete the preceding five steps to complete the modification.

Note: All described above are manually modified. If you want to modify it all at once, try the usermod-l command !~~

Usermod usage

Modify user account

Name

Usermod-Modify user account

Syntax

Usermod [-ccomment] [-dhome_dir [-m] [-eexpire_date] [-finactive_time] [-ginitial_group] [-Ggroup [,...] [-llogin_name] [-sshell] [-uuid [-o] login

Description

The usermod command modifies the system account according to the part specified in your command column. The following are optional parameters for usermod.

-Ccomment

Update the annotation column in the password file of the user account, which is generally modified using chfn (1.

-Dhome_dir

Update the user's new logon directory. Given the-m option, the old user directory will be moved to the new directory. If the old directory does not exist, a new one will be created.

-Eexpire_date

Add the user account stop date. The date format is MM/DD/YY.

-Finactive_days

The account will be permanently suspended several days after it expires. When the value is 0, the account is immediately suspended. If the value is-1, this function is disabled. The default value is-1.

-Ginitial_group

Updates the user's new initial logon group. The group name must already exist. The Group ID must refer to the existing group. The default group ID value is 1.

-Ggroup, [...]

Define the user as a group member. Used by each group ?? It cannot contain white spaces. The group name is limited by the-g option. If the current user group does not include this column, the user is removed from this group.

-Llogin_name

The name of the login user is changed to login_name. It remains unchanged. In particular, the user directory name should also be updated with the new login name.

-Sshell

Specify the new logon shell. If this field is left blank, the system selects the system preset shell.

-Uuid

The ID of the user. It must be a unique ID value unless the-o option is used. The number cannot be a negative value. By default, the minimum value must not be less than 99 and the value is increased progressively. 0 ~ 99 is traditionally reserved for system accounts. The userID of all the file directories under the user directory is automatically changed. Manually change the files stored outside the user directory.

Warning

Usermod does not allow you to change the name of an online user account. When usermod is used to change the userID, make sure that the user has not executed any program on the computer. You need to manually change the user's crontab file. You also need to manually change the user's at work file. The NISserver must be used to change the relevant NIS settings on the server.

Archives

/Etc/passwd-User Account Information/etc/shadow-User Account Information Encryption/etc/group-group information

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.