1)用这种一键脚本避免在密码中包含 $,可能会被 shell 解释为变量名。单独用passwd root设定时不存在这样的问题;
2)一键指令默认删除的其他用户名为admin,可以手动改成其他用户名,要想知道其他潜在要删除的用户名,可以用cat /etc/passwd指令查看。
#切换管理员权限:
sudo su -
#更改密钥登陆为密码登陆:
sudo sed -i -e '/^#\?\s*PermitRootLogin/s/^#\?\s*PermitRootLogin\s\+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
sudo sed -i -e '/^#\?\s*PasswordAuthentication/s/^#\?\s*PasswordAuthentication\s\+.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
#一键更改root密码为12345678
echo "root:12345678" | chpasswd
#删除admin多余账户:
sudo userdel -r admin
#重启SSH服务使得设置生效:
sudo systemctl restart sshd