Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Enable Root SSH Access in An Amazon EC2 Instance?

This issue has been bugging me for the past several days.

I've been working on setting up a LAMP Server on Amazon EC2. The main issue is that I'm writing an application for a client that requires a lot of high-end processing, and Amazon EC2 seemed like a good choice.

Initially I started off with a basic AMI which really didn't have anything. I tried using root access to log into SSH (using WinSCP) and I was told to use ec2-user.

I tried using ec2-user, and I was able to log in. However, I still didn't have root access and couldn't install apache. I did some reason and I found out about the "sudo" command, and pretty much every article I read on this issue said to either use root access, or log into ec2-user and user sudo.

I have since tried again with a different AMI where LAMP was already installed. I was able to get it working, set up a database and start running a website off of it. However, I still needed to install some extensions. Namely, an API I'm trying to use for this application requires SOAP to be installed.

Here's my dilemma:

/$ whereis soap soap: /$ whereis yum yum: /usr/bin/yum /etc/yum /etc/yum.conf /usr/share/man/man8/yum.8.gz /$ yum install php-soap Loaded plugins: fastestmirror, priorities, security You need to be root to perform this command. /$ sudo yum install php-soap sudo: sorry, you must have a tty to run sudo  Command 'sudo yum install php-soap' failed with return code 1 and error message sudo: sorry, you must have a tty to run sudo 

I can't use yum because I don't have root access, and whenever I log into root it either tells me to use ec2-user or provide a password I don't have. The other alternative was to use sudo to make ec2-user act like root, but I always get the error 'sorry, you must have a tty to run sudo.' I've ran that error message online and that it seems I need to add a user to sudoers... which I can't do without root access.

This exact same issue plagued me on two separate AMI's. On the first I just received a message saying I had to log in as ec2-user (and I must have a tty to run sudo), while the second (with LAMP installed) required me to enter a password for root, and for user I got the same sudo error.

Here are the id's of the AMI's I used:

ami-8c1fece5 ami-6ae81503 

I also tried a third AMI later that also had LAMP installed... I couldn't even get into that one at all.

I did download my SSH key and used PuttyGen to convert it to a ppk file. I can log in successfully as ec2-user, but I cannot gain root access anywhere.

I have been looking around quite a bit for help on this, but every article I've read assumes that the user either has root access available or has sudo available on ec2-user. I don't have either. Is it just that I need a new image?

Any help would be greatly appreciated...

like image 440
JaidynReiman Avatar asked Jul 09 '11 06:07

JaidynReiman


People also ask

How do I access EC2 instance SSH?

To connect from the Amazon EC2 consoleOpen the Amazon EC2 console. In the left navigation pane, choose Instances and select the instance to which to connect. Choose Connect. On the Connect To Your Instance page, choose EC2 Instance Connect (browser-based SSH connection), Connect.

Is EC2 user root user?

For a RHEL AMI, the user name is ec2-user or root . For a SUSE AMI, the user name is ec2-user or root . For an Ubuntu AMI, the user name is ubuntu . For an Oracle AMI, the user name is ec2-user .


1 Answers

I just tried

$ sudo su 

on one of your amis and voila! I am root...

Have fun!

[ec2-user@ip-10-244-146-238 ~]$ sudo su [root@ip-10-244-146-238 ec2-user]#  
like image 101
Alex Gitelman Avatar answered Sep 30 '22 17:09

Alex Gitelman