Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 '13 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." –  Michael Calkins Aug 14 '13 at 6:54
    
isn't the user www (not apache). I think the author mean 'the apache user, named www in ubuntu'. –  Drew Khoury Aug 15 '13 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. –  Michael Calkins Aug 15 '13 at 19:47
    
Are you replacing www with apache in your commands? –  Drew Khoury Aug 16 '13 at 1:21

1 Answer 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.

share|improve this answer
    
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. –  Michael Calkins Aug 15 '13 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." –  Drew Khoury Aug 16 '13 at 1:20

Your Answer

 
discard

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.