centos建立賬戶指令碼

潇潇暮鱼鱼發表於2024-05-30

指令碼

USER="appadmin"
CFG="/etc/ssh/sshd_config"
PASS=$(openssl rand -hex 16)
IP=$(ip a|grep inet| grep 10\.| awk '{print $2}'|awk -F '/' '{print $1}')
useradd ${USER}
sed -E -i 's/^#?( ?)*PasswordAuthentication.*$/PasswordAuthentication yes/' ${CFG}
systemctl restart sshd
echo ${PASS} | passwd ${USER} --stdin
echo "${USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USER}
cat << EOF 
初始化完畢, 連線資訊:
ssh ${USER}@${IP}
${PASS}
EOF

相關文章