0

I'm trying to setup this EC2 instance to listen for a webhook from Github and then run a git pull. The web runs this under the user 'apache'.

I was following: http://jondavidjohn.com/blog/2012/10/git-pull-from-a-php-script-not-so-simple

When I got the last part where you start running:

sudo -u www git pull

My server asks me for the password to "ec2-user". As far as I know you don't get that you just get a key and for the life of me I can't figure out how to run git pull.

From my apache error_log:

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

To my knowledge I need to add an SSH key but I can't because I don't know the password to ec2-user to run that command for the user 'apache'.

Me trying anything and everything:

<?php
// POST http://example.com/pull.php
putenv("HOME=/var/www/worker");

echo shell_exec("
#!/bin/sh
cd /var/www/html/worker/ || exit
unset GIT_DIR
git pull 2>&1
");

Anyone else run into this?

UPDATE

When I run sudo bash I am then running stuff as

[root@ip-10-233-33-33]#

When I run cat /etc/passwd I can confirm the account that I need to work with is named apache.

When I run su apache I get:

This account is currently not available.

6
  • You mention you just get a key. Have you done something to setup an SSH agent or adjust the SSH config so that the web user can find the key? Have you verified that the user PHP is running as has the permissions to read the key? Also, the 'host key verification' is about verifying that the server is who it says it is. Have you checked to make sure you don't have junk in your known_hosts?
    – Zoredache
    Aug 14, 2013 at 6:13
  • @Zoredache I am running ssh-agent as my user on the EC2 instance. When I try to create a key for that user 'apache' (that's the name from what I've read and www-data doesn't exist) my terminal asks me for the ec2-user password which you never receive. I've read that what's happening is that the server is trying to ask me to add it to my known_hosts or something. I can run git pull when I do "php pull.php" which runs just fine and I get that "Everything's up to date message." Aug 14, 2013 at 6:54
  • isn't the user www (not apache). I think the author mean 'the apache user, named www in ubuntu'. Aug 15, 2013 at 6:17
  • @DrewKhoury When I ran passwd or whatever the "List all users on this system" command is I had a user named "apache" not "www" or "www-data". Maybe it's because I'm on redhat or that's the way AWS sets up their AMI's. Aug 15, 2013 at 19:47
  • Are you replacing www with apache in your commands? Aug 16, 2013 at 1:21

1 Answer 1

1

Did you follow the whole article. In particular:

An easier way I discovered was to give the apache user a home directory (via /etc/passwd) and a .ssh directory and then run the ssh-keygen command as the apache user (www)

$> sudo -u www ssh-keygen -t rsa This creates the keys and puts them in their expected location with the proper permissions applied.

Then I added the key as a read-only key for the BitBucket repository and everything worked as expected.

2
  • When I run "sudo -u www ssh-keygen -t rsa" the -u arg asks me for ecw-user's password which you don't get when you create an EC2 instance you just get a pem-key file to ssh into it. Otherwise I'm sure I was on the right track until I hit that breaking point. Aug 15, 2013 at 19:49
  • It looks to me like it's asking for the www user password. "The -u (user) option causes sudo to run the specified command as a user other than root." Aug 16, 2013 at 1:20

You must log in to answer this question.

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