Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


AWS Fix Bash

17 Nov 2020 »

I know… not a fix

Allow root login

awsfix ()
{
    ip=$1;
    pemloc="<loc>"
    pubkey="<your pub key>"
    ssh -i $pemloc ec2-user@$ip "sudo sed -i \"s,#PermitRootLogin yes,PermitRootLogin yes,g\" /etc/ssh/sshd_config";
    ssh -i $pemloc ec2-user@$ip "echo '$pubkey' | sudo tee -a /root/.ssh/authorized_keys";
    ssh -i $pemloc ec2-user@$ip "nohup sleep 2; sudo systemctl restart sshd&"
}