M HYPE SPLASH
// news

AWS : How to switch as "root" user?

By John Peck

I have new created EC2 instance in aws, and able to login as EC2-user using private key but want to login as root to install packages. Not able to switch as root tried sudo - but it asking for password, I didn't creat any password for root yet. I am stuck here

3

2 Answers

For Amazon Linux 2 you can use sudo su

[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL=""
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ sudo su
[root@ip-xxx-xxx-xxx-xxx ec2-user]# whoami
root

It's working now, need to create password for root by typing "passwd" command and set password for root. To switch user "su root" command.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy