shell脚本创建用户
时间: 2023-10-12 11:20:44 浏览: 159
要在Linux系统上使用shell脚本创建用户,可以按照以下步骤进行:
1. 打开一个文本编辑器,例如Vi或Nano。
2. 在文本编辑器中输入以下命令:
```
#!/bin/bash
# This script creates a new user on the local system.
# You will be prompted to enter the username (login), the person name, and a password.
# The username, password, and host for the account will be generated automatically.
read -p "Enter the username for the new account: " username
read -p "Enter the full name of the user: " fullname
read -s -p "Enter the password for the new account: " password
echo
useradd -c "${fullname}" -m ${username}
echo "${username}:${password}" | chpasswd
echo "User account has been created successfully!"
```
3. 保存脚本文件并退出编辑器。
4. 授予脚本执行权限,使用以下命令:
```
chmod +x scriptname.sh
```
5. 运行脚本,使用以下命令:
```
./scriptname.sh
```
6. 按照提示输入新用户的用户名、全名和密码,然后按Enter键。
7. 脚本将自动创建新用户并设置密码。
注意:使用脚本创建用户时要小心,确保只为授权的用户创建帐户,并且密码必须是安全的。
阅读全文
相关推荐


















