Skip to content

Commit f380833

Browse files
committed
Adds support for passphrases in SSH keys and a more meaningful error message when there's something wrong logging in with the key.
1 parent 0d2dbf4 commit f380833

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

git-deploy

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,21 @@ class SFTP extends Server {
348348

349349
if (isset($server['sftp_key'])) {
350350
$key = new Crypt_RSA();
351+
if (isset($server['pass']) and !empty($server['pass'])) {
352+
$key->setPassword($server['pass']);
353+
}
351354
$key->loadKey(file_get_contents($server['sftp_key']));
352355
$logged_in = $this->connection->login($server['user'], $key);
356+
357+
if (!$logged_in) {
358+
error("Could not login to {$this->host}. It may be because the key requires a passphrase, which you need to specify it as the 'pass' attribute.");
359+
}
353360
} else {
354361
$logged_in = $this->connection->login($server['user'], $server['pass']);
355-
}
356-
357-
if (!$logged_in) {
358-
error("Could not login to {$this->host}");
362+
363+
if (!$logged_in) {
364+
error("Could not login to {$this->host}");
365+
}
359366
}
360367

361368
if (!$this->connection->chdir($server['path'])) {
@@ -640,6 +647,12 @@ class Config {
640647
$options['pass'] = self::promptPassword();
641648
}
642649

650+
if (isset($options['sftp_key'])) {
651+
if (substr($options['sftp_key'], 0, 2) == "~/") {
652+
$options['sftp_key'] = $_SERVER['HOME'].substr($options['sftp_key'], 1);
653+
}
654+
}
655+
643656
if ($options['skip']) {
644657
continue;
645658
} else {

0 commit comments

Comments
 (0)