Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

login using "ec2-user" instead of root using user data in aws

I have an Amazon EC2 instance based off of a RHEL 6.4 64bit AMI. After writing some shell scripts; I created my own AMI Image off of it.

I'm writing user data section which will remove the contents under /home/ec2-user(sudo rm -rf /home/ec2-user/*) and then execute that script. But i'm unable to remove any files.

what I want:

  • I want to remove files.
  • One more weird use case I've, by default user data section enters as "root" user but is there possibility to enter as "ec2-user" user and get my work done..?
like image 226
xyz123 Avatar asked Jul 01 '15 09:07

xyz123


2 Answers

User data always runs as root so don't use sudo. Below runs the cmd as ec2-user. If you want to start an executable do so in the background (ie. add & at the end)

su ec2-user -c 'do whatever you want; ./run.sh &'

like image 109
Koka Avatar answered Sep 16 '22 11:09

Koka


You cannot do it in the normal ec2-user account Do this command to be the deploy user ...

sudo su - deploy

which will then allow you to go to your app at the current location ...

cd /srv/www/sample_app/current
like image 30
Tache Avatar answered Sep 18 '22 11:09

Tache