In linux, force new users to log in and change their passwords for the first time.

Source: Internet
Author: User
Tags crypt epoch time
In linux, force a new user to log in and change the password for the first time. if the system administrator wants to add a user, set the user's password after the first login, the initial password or empty password must expire immediately, and the password must be changed immediately after the first login. Www... information & force a new user to log in and change the password for the first time in linux. if the system administrator wants to add a user, set the user's password after the first login, the initial password or empty password must expire immediately, and the password must be changed immediately after the first login. Www.2cto.com to force the user to set a new password for the first login, follow the instructions below. However, note that if the user logs in remotely through SSH, this method does not take effect. 1. lock user password-if the user does not exist, use useradd to add the user, but do not set the password, so that the account is still locked. if the user password has been activated, use the following command to lock it: usermod-L username2. force the password to expire immediately: chage-d 0 username this command sets the time when the user last modified the password to the epoch time (January 1, January 1, 1970), so that the command will immediately expire, regardless of the password expiration policy. 3. unlock an account-there are two methods to achieve this. the administrator can set a new password or set a blank password: Note: Do not use passwd to set a password, because it will invalidate the setting set to immediately expire the password. To set the initial password, follow these steps: start Python: # python Python 2.3.4 (#1, Feb 6 2006, 10:38:46) [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> enter the following command at the prompt: import crypt; print crypt. crypt ("userpassword", "username") output will be similar to: 12CsGd8FRcMSM input [Ctrl] + [D] to exit python. Copy the output password, 12CsGd8FRcMSM, and use the following command: usermod-p "12CsGd8FRcMSM" username. of course, you can also give the user an empty password: usermod-p "" username Note: Although empty passwords are convenient, there are security risks. After logging on to the user, the system prompts you to enter the password. Other methods: www.2cto.com can also be implemented using the following method: 1. use useradd to add a user 2. use passwd to set the user password 3. use usermod-L to lock the password 4. force the user account to expire chage-d 0 username 5. example of the above process for unlocking a user account: # useradd dan # passwd dan Changing password for user dan. new password: Retype new password: passwd: all authentication tokens updated successfully. # usermod-L dan # chage-d 0 dan # usermod-U dan of course, when user dan logs on for the first time, the system will prompt You to set the Password as follows: www.2cto.com $ su dan Password: You Re required to change your password immediately (root enforced) Changing password for dan (current) UNIX password: New password: Retype new password: This article is from redhat official documentation! According to my understanding, only two steps are required: 1. create a user account 2. force the user account to expire. if you need to clear the account, you only need to set the password field of the corresponding user in/etc/shadow (field ": separate, the second field) is cleared.
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.