首页 > 系统相关 >Ubuntu18创建用户

Ubuntu18创建用户

时间:2022-12-15 11:47:55浏览次数:42  
标签:username 创建 用户 echo Ubuntu18 password eq

#!/bin/bash
#############################
# 新增用户脚本
# 输入用户名、密码创建用户
#############################
usergropu="com"

 


if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -s /bin/bash -m -p $pass $username
gpasswd -a $username $usergropu
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi

标签:username,创建,用户,echo,Ubuntu18,password,eq
From: https://www.cnblogs.com/y593216/p/16984592.html

相关文章