我试图在服务器的部署中尽可能自动化,总体目标是以用户身份登录,上传bashscript并让它配置我的服务器如何配置。Bash脚本禁用root登录
要开始我试图禁用root登录,我知道我需要编辑/etc/ssh/sshd_config
到PermitRootLogin no
我想知道是否有办法通过一个bash脚本来做到这一点?
我试图在服务器的部署中尽可能自动化,总体目标是以用户身份登录,上传bashscript并让它配置我的服务器如何配置。Bash脚本禁用root登录
要开始我试图禁用root登录,我知道我需要编辑/etc/ssh/sshd_config
到PermitRootLogin no
我想知道是否有办法通过一个bash脚本来做到这一点?
如果你想只追加文本到的sshd_config文件,你可以使用printf
这样的:
printf '\n%s\n' 'PermitRootLogin no' >>/etc/ssh/sshd_config
,或者如果你想改变已经有一个值集的文件,但你想要设置为否,可以使用sed
这样的:
sed -i '/^PermitRootLogin[ \t]\+\w\+$/{ s//PermitRootLogin no/g; }' /etc/ssh/sshd_config
如果您正在部署服务器,则应该使用此工具。我提醒你“Ansible”。它会更容易(也更“优雅”)。
在这里,你有一个关于如何与Ansible http://ryaneschinger.com/blog/securing-a-server-with-ansible/
我希望我的回答可以帮助你禁用root登录教程!