Skip to content

[Proposal] use ssh-agent for remote connections #4235

@luchaos

Description

@luchaos

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.phpconnections array or even fall back to ssh-agent when none of password,keyor 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');
 ?>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions