Question : Following security audits, the xFusionCorp Industries security team has rolled out new protocols, including the restriction of direct root SSH login.
Your task is to disable direct SSH root login on all app servers within the Stratos Datacenter.
sshpass
to login to a remote server and execute the commands remotely without login on any servers. Please follow these steps. All the Best 👍
Solution:
1. In this task we will use sshpass to login to a remote server and edit the ssh_config
file, you can follow these steps.
thor@jump_host /$ sshpass -p Ir0nM@n ssh -o StrictHostKeyChecking=no tony@stapp01 "echo Ir0nM@n | sudo -S sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config"
sshpass -p Am3ric@ ssh -o StrictHostKeyChecking=no steve@stapp02 "echo Am3ric@ | sudo -S sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config"
sshpass -p BigGr33n ssh -o StrictHostKeyChecking=no banner@stapp03 "echo BigGr33n | sudo -S sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config"
|
2. Restart service: systemctl restart sshd && systemctl status sshd
thor@jump_host /$ |
sshpass -p Ir0nM@n ssh -o StrictHostKeyChecking=no tony@stapp01 "echo Ir0nM@n | sudo -S systemctl restart sshd && systemctl status sshd" sshpass -p Am3ric@ ssh -o StrictHostKeyChecking=no steve@stapp02 "echo Am3ric@ | sudo -S systemctl restart sshd && systemctl status sshd" sshpass -p BigGr33n ssh -o StrictHostKeyChecking=no banner@stapp03 "echo BigGr33n | sudo -S systemctl restart sshd && systemctl status sshd"
|
3. Validate the Changes run below commands
thor@jumphost ~$ thor@jumphost ~$ sshpass -p Ir0nM@n ssh -o StrictHostKeyChecking=no tony@stapp01 "echo Ir0nM@n | sudo -S grep -i ^Permit /etc/ssh/sshd_config" sshpass -p Am3ric@ ssh -o StrictHostKeyChecking=no steve@stapp02 "echo Am3ric@ | sudo -S grep -i ^Permit /etc/ssh/sshd_config" sshpass -p BigGr33n ssh -o StrictHostKeyChecking=no banner@stapp03 "echo BigGr33n | sudo -S grep -i ^Permit /etc/ssh/sshd_config" [sudo] password for tony: PermitRootLogin no [sudo] password for steve: PermitRootLogin no [sudo] password for banner: PermitRootLogin no thor@jumphost ~$ |
Happy Learning!!!!
0 Comments