如何自动用Bash脚本添加用户帐户和密码? [英] How to automatically add user account AND password with a Bash script?

查看:212
本文介绍了如何自动用Bash脚本添加用户帐户和密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的Linux(Fedora 10中)创建用户帐户,并自动通过bash脚本分配一个密码(或者,如果需要的话)的能力。

这很容易通过创建猛砸例如用户:

  [凡@服务器]#/ usr / sbin目录/ useradd的NEWUSER

是否有可能在分配猛砸功能与此类似,但密码,自动的东西:

  [凡@服务器]#passwd文件NEWUSER
用户testpass更改密码。
新的UNIX密码:
重新输入新的UNIX密码:
passwd文件:成功更新所有身份验证令牌。
[凡@服务器]#


解决方案

您可以运行passwd命令,并将其发送管道输入。那么,这样做:

 呼应thePassword | passwd文件theUsername --stdin

I need to have the ability to create user accounts on my Linux (Fedora 10) and automatically assign a password via a bash script(or otherwise, if need be).

It's easy to create the user via Bash e.g.:

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

Is it possible to assign a password in Bash, something functionally similar to this, but automatically:

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

解决方案

You can run the passwd command and send it piped input. So, do something like:

echo thePassword | passwd theUsername --stdin

这篇关于如何自动用Bash脚本添加用户帐户和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆