sshd_config 重启后自动更改规则

sshd_config automatically changes rules after reboot

在 AWS/EC2 的不同机器上,我在重启机器后不断更改 sshd 规则

原规则:

Match Group sftpusers
        ChrootDirectory /data/sftp/%u
        ForceCommand internal-sftp
        PasswordAuthentication yes

重启后修改规则:

Match Group sftpusers
ChrootDirectory /data/sftp/%u
ForceCommand internal-sftp
PasswordAuthentication no

所以基本上,这个组的用户无法验证sftp连接,这真的很烦人。

注意:PasswordAuthentication 默认设置为“否”。我只允许这组用户

有想法吗?

检查您有 /etc/cloud/cloud.cfg 或类似文件。我不确定它在 CentOS 中叫什么。寻找 ssh_pwauth 参数。

如果设置为0,表示密码验证将被禁用(通过sshd_config)。设置为 1 试试。

如果您使用的是 Amazon Linux ECS 优化的 AMI。

那么您需要将 /etc/cloud/cloud.cfg.d/00_defaults.cfg 更改为 ssh_pwauth: true

默认情况下 ssh_pwauth: false 每次重启后 PasswordAuthentication no

“请勿修改 00_defaults.cfg。如果升级 cloud-init,它将被覆盖。” AWS 有明确说明不要修改此文件。

相反,您可以在同一目录中添加另一个文件,将其命名为myconfigs.cfg。在该文件中,您可以添加以下行。

ssh_pwauth: true

这是一个更持久的解决方案。