在工作中,经常需要为Ubuntu添加用户,配置用户初始密码,配置组,通过脚本可以快速的实现这一工作:
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin GROUP_NAME=devs USER_CREATED=$* USER_PASSWD=ubuntu if [ "$1" != "" ]; then echo "Create User: $USER_CREATED" else echo "Please input username." exit 1 fi groupadd $GROUP_NAME if [ $(id -u) -eq 0 ]; then for USER_VAR in $USER_CREATED do id $USER_VAR > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "$USER_VAR exists!" else useradd -m -d /home/$USER_VAR -s /bin/bash -G $GROUP_NAME $USER_VAR echo $USER_VAR:$USER_PASSWD|chpasswd if [ $? -eq 0 ]; then echo "User ‘$TMP_USER_VAR‘ has been added to system!" else echo "Failed to add a user ‘$TMP_USER_VAR‘ !" fi fi done else echo "Only root can add a user to the system" exit 1 fi exit 0 #Author : brucemj
Ubuntu创建用户脚本
时间: 2024-10-14 12:13:45