Sshpass script to Automate Secure Root SSH Access Level 1 Linux KodeKloud Engineer Task Success

Ticker

6/recent/ticker-posts

Sshpass script to Automate Secure Root SSH Access Level 1 Linux KodeKloud Engineer Task Success

 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" 


thor@jump_host /$




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"

thor@jump_host /$


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 ~$


4.  Click on Finish & Confirm to complete the task successful

Happy Learning!!!!

Post a Comment

0 Comments

Latest Posts

Create EC2 Instance Using Terraform  Kodekloud Engineer Task Success