Aphire
Aphire

Reputation: 1652

Git deploy script fails, but SSH doesn't

A developer where I work has recently left, and I've been tasked with recycling all of our keys etc.

We use BitBucket for our source control and this particular developer has a "pull script" running on one of our servers that would pull anything from our development branch onto a test version of the site. After we removed his Atlassian account, it took the SSH key this deploy script used with it. I have since generated new keys, uploaded the public to my Atlassian account, and placed the private on the server, so far so good.

However his deploy script returns Permission denied (publickey).

When I try $ ssh [email protected] I get the following:

PTY allocation request failed on channel 0
logged in as ChocolateDinosaur.

You can use git or hg to connect to Bitbucket. Shell access is disabled.
Connection to bitbucket.org closed.

Which appears to work? (Forgive my ignorance if this is not the case)

The deploy script is as follows:

<?php
$commands = array(
    'echo $PWD',
    'whoami',
    'git pull',
    'git status',
    // 'git submodule sync',
    // 'git submodule update',
    // 'git submodule status',
);

$output = '';
foreach($commands AS $command){
    $tmp = shell_exec($command);
    $output .= "<span style=\"color: #6BE234;\">\$</span> <span style=\"color: #729FCF;\">{$command}\n</span>";
    $output .= htmlentities(trim($tmp)) . "\n";
}
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>GIT DEPLOYMENT SCRIPT</title>
</head>
<body style="background-color: #000000; color: #FFFFFF; font-weight: bold; padding: 0 10px;">

<pre>
<?=$output?>
</pre>

</body>
</html>

Source control is certainly not my forte and I see it as a necessary evil, I am assuming that the reason the script fails is that git on our server is either pointing to github rather than bitbucket, or still trying to use some of the previous developers credentials?

I have changed the git config --global user.name and git config --global user.email to try and combat this.

Any suggestions would be greatly appreciated.

Upvotes: 0

Views: 66

Answers (1)

zigarn
zigarn

Reputation: 11625

The SSH key need to be available to the user running your PHP script.

So take a look at Generating SSH keys for 'apache' user and this answer.

BTW, user.email and user.name are for identification in commit data, authentication is done with SSH username and password, SSH key or HTTP authentication, with no relation to commit identification data.

Upvotes: 1

Related Questions