Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got an amazon EC2 instance, which starts up, runs a script, and when the script finishes, I want to shut it down.

I tried chmod g+s to give super user privileges on a .sh script which called shutdown, but that didnt work. Is there another way?

Or should I use the amazon API instead?

share|improve this question
up vote 10 down vote accepted

Assuming you are using Linux-based instance.

Use sudo to grant your script user permission to run shutdown with root privileges.

edit your sudoers file with visudo and put this line

scriptuser    ALL = NOPASSWD: /sbin/shutdown

After that your script can shutdown machine with command /usr/bin/sudo /sbin/shutdown

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.