40 lines
955 B
Bash
40 lines
955 B
Bash
#!/bin/bash
|
||
username=$1
|
||
homedir="/data/"
|
||
num=1
|
||
check_command() {
|
||
if [ $? -ne 0 ]; then
|
||
let num = $num + 1
|
||
exit 1 # 退出脚本并返回错误状态
|
||
fi
|
||
}
|
||
|
||
mkdir -p $homedir/$usernames
|
||
check_command
|
||
chown -R $username:$username $homedir/$username
|
||
check_command
|
||
useradd -m -d $homedir/$username -s /bin/bash $username
|
||
check_command
|
||
password= $(openssl rand -base64 48 | cut -c1-6)
|
||
echo "$password" | passwd --stdin $username
|
||
check_command
|
||
chown -R $username:$username $homedir/$username
|
||
check_command
|
||
usermod -aG docker $username
|
||
check_command
|
||
newgrp docker
|
||
check_command
|
||
read -p "是否需要sudo权限(y/n):" yn
|
||
if [ $yn = "是" ]; then
|
||
usermod -aG sudo $username
|
||
fi
|
||
echo "用户创建成功!"
|
||
echo "================================================================"
|
||
IP=$(curl ifconfig.me)
|
||
echo "公网IP:$IP"
|
||
ip=$(hostname -I)
|
||
echo "内网IP(默认使用第一个):$ip"
|
||
echo "用户名:$username"
|
||
echo "密码:$password"
|
||
|