#!/bin/bash
#添加用户,赋予密码
useradd -s /bin/bash -d /home/ybsre -m ybsre
echo Dec_2019op | passwd --stdin ybsre
#加入sudo权限
echo "ybsre ALL=(ALL) NOPASSWD: ALL">> /etc/sudoers.d/ybsre
chmod 744 /etc/sudoers.d/ybsre
#改变用户有效时长
chage -M 9999 ybsre
#重启sshd服务
service sshd reload
systemctl restart sshd

#添加远程登录免密密匙
#判断是否存在ybsre免密目录,否则创建
if [ ! -d /home/ybsre/.ssh]
then
  mkdir -pv /home/ybsre/.ssh
fi
#传入公钥 id_rsa.pub 的内容
echo 'ssh-rsa xxxxxxxx' >> /home/ybsre/.ssh/authorized_keys
#修改目录权限和属主
chown -R ybsre.ybsre /home/ybsre/.ssh
chmod 600 /home/ybsre/.ssh/authorized_keys

 

相关文章:

  • 2021-04-04
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2021-06-29
  • 2022-03-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-25
  • 2022-02-08
  • 2021-11-01
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案