4

I am baking an image on top of Amazon linux image. I need to run a service as ec2-user. Is it possible to run a launch script of any kind as user other than root?

Łukasz
  • 1,980
  • 6
  • 32
  • 52

2 Answers2

0

I'm assuming you're going to put the command under UserData.

Scripts entered as user data are executed as the root user, so do not use the sudo command in the script. Remember that any files you create will be owned by root; if you need non-root users to have file access, you should modify the permissions accordingly in the script. Also, because the script is not run interactively, you cannot include commands that require user feedback (such as yum update without the -y flag).

Here's the full documentation discussing topic

gzz
  • 655
  • 5
  • 18
  • There is actually a mistake in the documentation you reference where `sudo` is used and is not necessary: `sudo systemctl enable httpd` – John Hanley Sep 03 '18 at 22:10
0

Use this:

su ec2-user -c 'your commands go here'
Chau Giang
  • 1,414
  • 11
  • 19