3

I have to run this command to initialize gitosis:

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

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

$ sudo -H -u git gitosis-init < id_rsa.pub
[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?

Update:

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

3
  • should i move this question to superuser or stackoverflow or somewhere else?
    – bool.dev
    Oct 30, 2012 at 16:51
  • What EC2 region are you running in? What AMI id did you start with? Oct 30, 2012 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.
    – bool.dev
    Oct 30, 2012 at 22:33

3 Answers 3

5

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/id_rsa.pub

Please don't kick yourself too hard.

1
  • i'll try not to :) . didn't know you could do that actually, awesome.
    – bool.dev
    Oct 31, 2012 at 7:25
2

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/id_rsa.pub
    
  5. exit from git user, then exit from root.


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

1

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.

1
  • awesome, i did read something like this while searching for a solution but was unsure (then) if it'll work, good alternate method, thanx.
    – bool.dev
    Oct 31, 2012 at 17:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .