I'm trying to automate as much as possible in the deployment of servers, the overall goal is to login as a user, upload a bashscript and have it configure my server how I need it configured.
To start I'm trying to disable root login, I know I have to edit /etc/ssh/sshd_config to PermitRootLogin no
I was wondering if there was a way to do this via a bash script?
If you want to just append your text to the sshd_config file, you could use printf like this:
printf '\n%s\n' 'PermitRootLogin no' >>/etc/ssh/sshd_config
or if you want to change a file that already have a value set, but you want to set it to no, could use sed like this:
sed -i '/^PermitRootLogin[ \t]\+\w\+$/{ s//PermitRootLogin no/g; }' /etc/ssh/sshd_config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With