Get AWS EC2 root and Change Login Way
Instroduce
When you launch a EC2 instance, the default:
- You have to use .pem(chmod 400 before use) for ssh login.
- You will only centos(or ec2-user) account for login(user permission)
And ofcourse you have only user permission.
STEP by STEP
Login to EC2 by default:
$ chmod 400 my-key-pair.pem $ ssh -i my-key-pair.pem centos@{public ip}
Switch permission from user to root:
$ sudo su
Then you are able to change root password and do any root things.
Modify ssh to allow root login:
# vi /etc/ssh/sshd_config
Chenge:PermitRootLogin yes
Save and Exit.
Modify ssh allow password login:
# vi /etc/ssh/sshd_config
Change:PasswordAuthentication yes
Save and Exit.
Modify allow use .pem file for root login:
vi /root/.ssh/authorized_keys
Remove below section:command="echo 'Please login as the ec2-user user rather than root user.';echo;sleep 10"
Save and Exit.
Restart sshd:
# service sshd restart
You are now get root permission and able to login by password and .pem file.