看起来你想要通过脚本直接修改SSH配置来允许root登录并启用密码认证。然而,PermitRootLoginPasswordAuthentication这两个指令是/etc/ssh/sshd_config文件中的配置选项,不能直接通过set命令在bash脚本中设置。set命令在shell脚本中用于设置或取消设置shell选项和位置参数,或者显示shell变量的名称和值。

如果你想要通过脚本修改SSH配置来允许root登录并启用密码认证,你需要编辑/etc/ssh/sshd_config文件。以下是一个bash脚本示例,使用sed(流编辑器)命令来自动修改这些配置:

#!/bin/bash

# 备份原始的sshd_config文件
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

# 允许root登录
sudo sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
sudo sed -i 's/^PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config

# 启用密码认证
sudo sed -i 's/^#PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
sudo sed -i 's/^PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config

# 重启SSH服务使配置生效
sudo systemctl restart sshd

这个脚本首先备份了原始的sshd_config文件,以防万一需要回滚。然后,使用sed命令替换(或取消注释并替换)PermitRootLoginPasswordAuthentication设置为yes。最后,脚本重启SSH服务以应用更改。

**注意:**在运行这种修改系统配置的脚本之前,请确保你了解它们的作用和潜在影响。修改sshd_config并重启SSH服务可能会影响到你对服务器的远程访问。此外,允许root登录和密码认证可能会带来安全风险,确保你了解并采取了必要的安全措施。

Logo

一起探索未来云端世界的核心,云原生技术专区带您领略创新、高效和可扩展的云计算解决方案,引领您在数字化时代的成功之路。

更多推荐