linux - 如何使用 Bash 脚本自动添加用户帐户和密码?

我需要能够在我的 Linux (Fedora 10) 上创建用户帐户并通过 bash 脚本(或其他方式,如果需要)自动分配密码。

通过 Bash 创建用户很容易,例如:

[whoever@server ]#  /usr/sbin/useradd newuser

是否可以在 Bash 中分配密码,功能类似于此,但自动:

[whoever@server ]# passwd newuser
Changing password for user testpass.
New UNIX password:
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[whoever@server ]#

最佳答案

您也可以使用 chpasswd :

echo username:new_password | chpasswd

因此,您将用户 username 的密码更改为 new_password

https://stackoverflow.com/questions/2150882/

相关文章:

linux - 如何将命令行参数传递给 unix/linux 系统上正在运行的进程?

python - 如何从文件中读取特定行(按行号)?

linux - 如何规范化 Bash 中的文件路径?

python - 如何在 Flask-SQLAlchemy 应用程序中执行原始 SQL

python - Google 大量使用 Python

linux - 如何获取进程 ID 以杀死 nohup 进程?

python - 在python中将 float 转换为整数的最安全方法?

python - 找出 Python 中的对象正在使用多少内存

linux - Bash 脚本并行处理有限数量的命令

linux - bash 中是否有 "goto"语句?