Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 have to run this command to initialize gitosis:

sudo -H -u git gitosis-init < /home/ec2-user/

But that asks me for a password for ec2-user:

$ sudo -H -u git gitosis-init <
[sudo] password for ec2-user: 

I do not have a password as i use the default .pem key file to login.

I know i can probably login as the git user and do this, but is there any other way?


Using Linux AMI 12.09 (micro-instance), in region us-east-1 (N. Virginia)

share|improve this question
should i move this question to superuser or stackoverflow or somewhere else? – Oct 30 '12 at 16:51
What EC2 region are you running in? What AMI id did you start with? – Eric Hammond Oct 30 '12 at 22:10
@EricHammond please see update. I do have a workaround, see answer, but still looking for a better solution if possible, not sure if the workaround is best possible solution here. – Oct 30 '12 at 22:33
up vote 4 down vote accepted

As you discovered, the root user can sudo to any other user, so just stick an extra sudo in front.

sudo sudo -H -u git gitosis-init < /home/ec2-user/

Please don't kick yourself too hard.

share|improve this answer
i'll try not to :) . didn't know you could do that actually, awesome. – Oct 31 '12 at 7:25

This is my current workaround:

  1. First login as ec2-user with the .pem file

  2. Then switch to root with sudo su

  3. Then switch to git user with su git

  4. Then run the gitosis-init like so:

    gitosis-init < path/to/
  5. exit from git user, then exit from root.

Note: I had added the git user with just sudo adduser git

share|improve this answer

You want to update /etc/sudoers to allow you to run commands as git without requiring a password.

First, edit the sudoers file:

$ EDITOR=my_favorite_text_editor sudo -E visudo

Add the following line at the end*:

ec2_user  ALL=(git) NOPASSWD: gitosis-init

You can then use the command that you've been using, but you will no longer be prompted for a password.

* Or you can add that to a file in /etc/sudoers.d, if you have that available.

share|improve this answer
awesome, i did read something like this while searching for a solution but was unsure (then) if it'll work, good alternate method, thanx. – Oct 31 '12 at 17:48

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.