如何通过自动化将“PasswordAuthentication”设置为“是”

use*_*955 5 14.04

在 Ubuntu 16.4 EC2 中,默认情况下,虚拟启动的计算机中没有密码身份验证。这不方便,因为我想添加新用户并允许他们使用密码登录。我希望使用 bash 脚本或命令自动执行此手动活动。

我的参考问题:无法登录我创建的新用户,显示权限被拒绝(公钥)而不询问密码

现在我手动将PasswordAuthentication更改为yes,然后“service sshd reload”。

use*_*955 6

以下命令有效:

将以下内容保存为脚本文件,例如 example.sh

#!/bin/bash
# sudo sed -i "/^[^#]*PasswordAuthentication[[:space:]]no/c\PasswordAuthentication yes" /etc/ssh/sshd_config
# sudo service sshd restart
Run Code Online (Sandbox Code Playgroud)

将上述命令保存到脚本中后运行脚本。

# sudo ./example.sh
Run Code Online (Sandbox Code Playgroud)