ubuntu服务器初始化脚本

最近买了几台云主机,写了个脚本初始化用户和权限

  1. 创建一个无密码的新用户
  2. 开启SSH登录
  3. 设为SUDOUser
  4. 禁用root用户
#!/bin/bash
NEWUSER='fyn'
IDRSA_PUB="*****"
useradd -m ${NEWUSER}
mkdir /home/${NEWUSER}/.ssh
echo ${IDRSA_PUB} > /home/${NEWUSER}/.ssh/authorized_keys
chown ${NEWUSER}:${NEWUSER} -R /home/${NEWUSER}
chmod 0600 /home/${NEWUSER}/.ssh/authorized_keys
echo -e "\n${NEWUSER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
chsh -s /bin/bash ${NEWUSER}
echo -e "\n127.0.0.1 $(hostname)" >> /etc/hosts
passwd -l root

发表评论

邮箱地址不会被公开。 必填项已用*标注