天天看點

linux 使用者密碼加密

生成加密密碼

#!/usr/bin/python
import crypt,random,string;
print(crypt.crypt("123456", '$6$' + ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(16)])));
print(crypt.crypt("123456", '$6$' + ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(16)])));      

 其中$6$表示密碼加密方式為sha512

通過kickstart自動化安裝系統

設定root密碼

rootpw --iscrypted $6$uiq8l/7xEWsYXhrvaEgan4N21yhLa8K.U7UA12Th3PD11GOXvEcI40gp1

設定普通使用者密碼

Syntax
user --name=username [options]

Below are some of the options which can be used with above syntax

--name= - Provides the name of the user. This option is required.
--gecos= - Provides the GECOS information for the user. This is a string of various system-specific fields separated by a comma. It is frequently used to specify the user's full name, office number, and so on. See the passwd(5) man page for more details.

--groups= - In addition to the default group, a comma separated list of group names the user should belong to. The groups must exist before the user account is created. See the group command.

--homedir= - The home directory for the user. If not provided, this defaults to /home/username.

--lock - If this option is present, this account is locked by default. This means that the user will not be able to log in from the console. This option will also disable the Create User screens in both the graphical and text-based manual installation.

--password= - The new user's password. If not provided, the account will be locked by default.

--iscrypted - If this option is present, the password argument is assumed to already be encrypted. This option is mutually exclusive with --plaintext.

--shell= - The user's login shell. If not provided, the system default is used.

--uid= - The user's UID (User ID). If not provided, this defaults to the next available non-system UID.

--gid= - The GID (Group ID) to be used for the user's group. If not provided, this defaults to the next available non-system group ID.      

user --name=dee --groups=whe --iscrypted --password=$6$NQxcaeY.Pvm1FWBl$LriLt5PFtqUUs0sJgUhpAwOc4n9dwJ0sx1qPDVXHZzXq0GnA8ZpuLkJG9QoGb5JwUv2/3JZLJBjDTUJXIP3bS

通過usermod修改使用者密碼

-p, --password PASSWORD       use encrypted password for the new password

usermod -p '$6$NQxcaeY.Pvm1FWBl$LriLt5PFtqUUs0sJgUhpAwOc4n9dwJ0sx1qPDVXHZzXq0GnA8ZpuLkJG9QoGb5JwUv2/3JZLJBjDTUJXIP3bS'  username

參考

繼續閱讀