简体   繁体   English

Python:如何使用Fabric在ubuntu用户帐户上设置密码

[英]Python: How do I set the password on an ubuntu user account using Fabric

I'm trying to create a user account on a remote Ubuntu system using Fabric. 我正在尝试使用Fabric在远程Ubuntu系统上创建用户帐户。 I want the account to have a strong password. 我希望该帐户具有强密码。 I can use the following to create the account: 我可以使用以下方法创建帐户:

 sudo('useradd -m test -s /bin/bash')

The problem is I'm not sure how to set the password. 问题是我不确定如何设置密码。 The useradd -p options requires an encrypted password. useradd -p选项需要一个加密的密码。 How do I set the password? 如何设置密码? How does the salt get passed to the remote system? 盐如何传递到远程系统?

Example code would be appreciated. 示例代码将不胜感激。

Thanks 谢谢

I do it like this: 我这样做是这样的:

sudo('useradd %s' % username)
sudo('echo %s | passwd %s --stdin' % (username, username))
sudo('chage -d 0 %s' % username)

The password will match the username and the user will be prompted to change their password at first login. 密码将与用户名匹配,并在首次登录时提示用户更改密码。

Try chpasswd . 尝试chpasswd Unlike passwd , you can pass the username and password in the command's standard input. passwd不同,您可以在命令的标准输入中传递用户名和密码。 So you can for example upload a file containing the password and put this line in your fabfile: 因此,您可以例如上载包含密码的文件,并将此行放入fabfile中:

sudo('chpasswd < my_password_file')

From man chpasswd : 来自man chpasswd

The chpasswd command reads a list of user name and password pairs from standard input and uses this information to update a group of existing users. chpasswd命令从标准输入中读取用户名和密码对的列表,并使用此信息来更新一组现有用户。 Each line is of the format: 每行的格式为:

user_name:password 用户名密码

The supplied passwords must be in clear-text. 提供的密码必须为明文形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM