1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #!/bin/sh USERNAME=[username]
# 1代表有sudo权限,0代表普通用户 SUDO_FLAG=1
PUBKEY="ssh-rsa xxx"
if id "${USERNAME}" &>/dev/null; then echo 'adduser: user '${USERNAME}' already exists' exit 0 else adduser ${USERNAME} mkdir /home/${USERNAME}/.ssh chmod 700 /home/${USERNAME}/.ssha touch /home/${USERNAME}/.ssh/authorized_keys chmod 600 /home/${USERNAME}/.ssh/authorized_keys echo ${PUBKEY} >> /home/${USERNAME}/.ssh/authorized_keys chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.ssh/* chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.ssh
#depends whether sudo right is needed for the user if [ $SUDO_FLAG -eq 1 ]; then touch /etc/sudoers.d/${USERNAME} echo ${USERNAME}' ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/${USERNAME} echo yi.chen' ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/yi.chen chmod 640 /etc/sudoers.d/${USERNAME} fi fi
chage -I -1 -m 0 -M 99999 -E -1 ${USERNAME}
if [ $? -eq 0 ]; then echo 'Success! Created user '${USERNAME}' ' else echo 'Failed! user:'${USERNAME}'' fi
|