-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Description
phpseclib allows to use the system's ssh-agent for providing the key for ssh connections since two months. Laravel does not seem to provide this option next to username/password and private_key/passphrase authentication for remote connections.
Background:
Searching for the reason why both the passphrase for and the path to private keys have to be provided (see related stackoverflow question) I found out that phpseclib does indeed have an undocumented implementation for ssh-agent but Laravel does not make use of this method in its SecLibGateway.
Implementation ideas:
Either allow to set key
to true
in config/remote.php
connections array or even fall back to ssh-agent when none of password
,key
or keyphrase
is set.
Another option could be to add another config field like agent
accepting Booleans specifically for this, which seems unnecessary to me, though.
config/remote.php
return array(
'default' => 'production',
'connections' => array(
'production' => array(
'host' => 'serverhaspublickey.com',
'username' => '',
'password' => '',
'key' => true, // invokes ssh-agent
'keyphrase' => '',
'root' => '/var/www',
),
),
laravel/framework/src/Illuminate/Remote/SecLibGateway.php
Either extend getAuthForLogin()
or loadRsaKey()
with an according routine to pass an instance of System_SSH_Agent
instead of Crypt_RSA
to login()
at line 85.
As it may be done and can be seen in the source file's header comment here
Works both with phpseclib's SSH2 and SFTP:
<?php
include('System/SSH/Agent.php');
include('Net/SSH2.php');
$agent = new System_SSH_Agent();
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', $agent)) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
?>