Skip to main content

Command Palette

Search for a command to run...

Change default password of root user on aws ubuntu ec2 instance

Published
1 min read
S

I am CS Student currently perusing my bachelor degree. I love coding and implementing new logics. Aside from that I'm also a hardware lover and has great interest in IOT.

First ssh into your server using the ssh key.

ssh -i "Mysecretkey.pem" ubuntu@ec2-ip.compute-1.amazonaws.com

Once you are logged in, switch to root user with the following command

sudo su

If successful, you will be switched to root.

Optional:

If you want to enable the root level login, then run this one liner command to enable root login

sed -i -e 's/.*exit 142" \(.*$\)/\1/' /root/.ssh/authorized_keys

Then run passwd root

It will ask for the new password

New password: // Enter new password here
Retype new password: // Re-Enter new password here

Once everything is correct, you will get the success message

passwd: password updated successfully

Congratulations, you have successfully changed your root password.

Also, to change the password of the specific user, you can repeat the same procedure, just provide the different username with the switch user (su) command.

That's it !

82 views