Usermod commands and passwd commands for the Linux command

Source: Internet
Author: User
Tags crypt

Usermod command parameters and usage details (Linux Modify user account information command)

Linux usermod command parameters and usage details, Linux Modify user account Information command, USERMOD can be used to modify the user account settings

Command: Usermod

Function Description: Modify user account.

Syntax: Usermod [-lu][-c < remarks >][-d < login directory >][-e < expiration >][-f < buffer days >][-g < group >][-g < group >][-l & lt; account name >][-s <shell>][-u <uid>][user Account]

Additional note: Usermod can be used to modify the user account settings.

Parameters

-c< Notes > Modify the Notes text for the user account.
-D Login Directory > Modify user login directory.
-e< Expiration date > Modify the expiration date of the account.
-f< Buffer days > Modify the number of days after the password expires to close the account.
-g< Group > Modify the group to which the user belongs.
-g< Group > Modify the additional groups to which the user belongs.
-l< Account name > Modify user account name.
-L LOCKS the user password to invalidate the password.
-s<shell> modifies the shell used by the user when they log in.
-u<uid> Modify the User ID.
-U unlocks the password.

Usermod does not allow you to change the user account name on the line. When Usermod is used to change the user ID, it must be confirmed that the user is not executing any programs 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. Using NIS server requires that the relevant NIS settings be changed on the server.

Application Examples:

1. Add Newuser2 to the group staff
# USERMOD-G Staff Newuser2
2, modify the NewUser user name is Newuser1
# usermod-l Newuser1 NewUser
3. Lock Account Newuser1
# usermod-l Newuser1
4, release the lock on the Newuser1
# usermod-u Newuser1



Summary of practical tips for passwd commands

Let's review the basic usage of the passwd command:
The Linux passwd command is used to change the user's password
Grammar
passwd [-K] [-l] [-u [-f]] [-d] [-S] [username]
Necessary parameters:
-D Remove Password
-F Force Execution
-K updates can only be sent after expiration
-L Stop Account usage
-S Display password information
-U enable an account that has been stopped
-X Set the validity period of the password
-G Modify Group password
-I stop user account after expiration
Select parameters:
--HELP Display Help information
--version displaying version information
Instance
Modify User Password

Copy Code

The code is as follows:


# passwd W3cschool// set W3cschool user's password
Enter new UNIX Password://Enter password, no echo
Retype new UNIX Password://Confirm Password
Passwd:password updated successfully
#


Show account password information

Copy Code

The code is as follows:


# passwd-s W3cschool
W3cschool P 05/13/2010 0 99999 7-1


Delete User Password

Copy Code

The code is as follows:


# passwd-d lx138
Passwd:password expiry information changed.

OK, let's take a look at the actual application scenario:
Example 1: Changing the password for a system user

When you log in using a non-root user, such as when I log in with ' Linuxtechi ', running the passwd command resets the password of the currently logged-on user.

Copy Code

The code is as follows:


[Email protected] ~]$ passwd
Changing password for user Linuxtechi.
changing password for Linuxtechi.
(current) UNIX Password:
New Password:
Retype new Password:
Passwd:all authentication tokens updated successfully.
[Email protected] ~]$


When you log in as a root user and run the passwd command, it resets the root password by default, and if you specify a user name after the passwd command, it will reset the user's password.

Copy Code

The code is as follows:


[Email protected] ~]# passwd
[Email protected] ~]# passwd Linuxtechi


650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/8D/F9/wKioL1iyM__idnwuAACVNrEuG0o763.png-wh_500x0-wm_ 3-wmp_4-s_767831549.png "title=" 1.png "alt=" Wkiol1iym__idnwuaacvnreug0o763.png-wh_50 "/>

Note: The password of the system user is saved in an encrypted form in the/etc/shadow file.

Example 2: Show password status information

To display status information for a user's password, use the-s option after the passwd command.

Copy Code

The code is as follows:


[Email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 2015-09-20 0 99999 7-1 (Password set, SHA512 crypt.)
[Email protected] ~]#


In the above output, the first field displays the user name, the second field shows the password status (PS = password setting, LK = password lock, NP = no password), the third field shows the last time the password was modified, and the next four fields show the minimum and maximum age for which the password can be changed. The duration of the warning and the length of time when the password was not used.

Example 3: Show password status information for all accounts

In order to display the status information for all user passwords, you need to use the "-as" option in the passwd command, as shown in the following example:

Copy Code

The code is as follows:


[Email protected]:~# Passwd-sa


650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/8D/F9/wKioL1iyNAqDn6HIAADUi2lJl6w715.jpg-wh_500x0-wm_ 3-wmp_4-s_1332569127.jpg "title=" 2.jpg "alt=" Wkiol1iynaqdn6hiaadui2ljl6w715.jpg-wh_50 "/>

(LCTT : Different distributions/passwd behave differently.) CentOS6.6 did not test successfully, but Ubuntu can. )

Example 4: Remove a user's password by using the-D option

With my example, delete the ' Linuxtechi ' user's password.

Copy Code

The code is as follows:


[Email protected] ~]# passwd-d Linuxtechi
Removing password for user Linuxtechi.
Passwd:success
[Email protected] ~]#
[Email protected] ~]# passwd-s Linuxtechi
Linuxtechi NP 2015-09-20 0 99999 7-1 (Empty password.)
[Email protected] ~]#


"-D" option clears the user password and disables user login.

Example 5: Set the password to expire immediately

Using the '-e ' option in the passwd command immediately expires the user's password, which forces the user to change the password at the next logon.

Copy Code

The code is as follows:


[Email protected] ~]# passwd-e Linuxtechi
Expiring password for user Linuxtechi.
Passwd:success
[Email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 1970-01-01 0 99999 7-1 (Password set, SHA512 crypt.)
[Email protected] ~]#


Now try to connect to the host with Linuxtechi user ssh.
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/8D/FB/wKiom1iyNBTgxp6ZAADUi2lJl6w589.jpg-wh_500x0-wm_ 3-wmp_4-s_2318909464.jpg "title=" 3.jpg "alt=" Wkiom1iynbtgxp6zaadui2ljl6w589.jpg-wh_50 "/>

Example 6: Lock the System user's password

Using the '-l ' option in the passwd command locks the user's password, and it adds "!" to the beginning of the password. When his/her password is locked, the user will not be able to change its password.

Copy Code

The code is as follows:


[Email protected] ~]# passwd-l Linuxtechi
Locking password for user Linuxtechi.
Passwd:success
[Email protected] ~]# passwd-s Linuxtechi
Linuxtechi LK 2015-09-20 0 99999 7-1 (Password locked.)
[Email protected] ~]#


Example 7: Unlocking a user's password with the-u option

Copy Code

The code is as follows:


[Email protected] ~]# passwd-u Linuxtechi
Unlocking password for user Linuxtechi.
Passwd:success
[Email protected] ~]#


Example 8: Using the-I option to set inactivity time

Use the-i option in the passwd command to set the inactivity time of the system user. Users will not be able to log in if the user (I am using a Linuxtechi user) expires after the user has passed ' N ' Days (10 days in my case) without changing their password.

Copy Code

The code is as follows:


[Email protected] ~]# passwd-i Linuxtechi
Adjusting aging data for user Linuxtechi.
Passwd:success
[Email protected] ~]#
[Email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 2015-09-20 0 99999 7 (Password set, SHA512 crypt.)
[Email protected] ~]#


Example 9: Setting the minimum time for password changes using the-N option

In the following example, the Linuxtechi user must change the password within 90 days. 0 means that the user can change its password at any time.

Copy Code

The code is as follows:


[Email protected] ~]# passwd-n Linuxtechi
Adjusting aging data for user Linuxtechi.
Passwd:success
[Email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 2015-09-20 99999 7 (Password set, SHA512 crypt.)
[Email protected] ~]#


Example 10: Use the-w option to set the warning period before the password expires

'-W ' options are used in the passwd command to set the user's warning period. This means that after n days, his/her password will expire.

Copy Code

The code is as follows:


[Email protected] ~]# passwd-w Linuxtechi
Adjusting aging data for user Linuxtechi.
Passwd:success
[Email protected] ~]# passwd-s Linuxtechi
Linuxtechi PS 2015-09-20 99999 (Password set, SHA512 crypt.)
[Email protected] ~]#


This article from "Peng Brother's Blog" blog, declined reproduced!

Usermod commands and passwd commands for the Linux command

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.