SSH Connection always ask for ssh key passphrase
mateusjunges opened this issue · 4 comments
Good night,
I'm giving this package a try, and here is how i am connecting to my ssh host:
\Spatie\Ssh\Ssh::create('MY USER', 'MY HOST')
->usePort(2222)
->usePrivateKey('path to my key file')
->execute('ls -la')
->getOutput()
Then, i run php artisan serve
, and, in my linux terminal, this is the output:
started
[Fri Feb 14 00:08:36 2020] 127.0.0.1:44010 Accepted
[Fri Feb 14 00:08:36 2020] 127.0.0.1:44012 Accepted
Enter passphrase for key 'path_to_my_key_file':
What i am doing wrong? Can't figure out what am i missing.
Thanks!
Hi @mateusjunges,
Seems like your private key is protected by a passphrase, could you try connecting to the host via ssh in the command line first? Normally you should provide a passphrase and then you're good to go. Maybe we should add support for providing passphrase, though I have no idea at the moment how we could do this.
You are right, my Private key is protected by passphrase. Connecting to the host via terminal just work fine, and I need to type my passphrase only for the first connection. Then, I click the checkbox telling Linux to unlock my key file as soon as I log in to my PC. But, unfortunately, it doesn't work with spatie/ssh
, and it ask for my passphrase for each connection.
Support for providing a passphrase would be awesome, but I don't know how to do it now. Will take some time to think about it.
Thanks!
To not having to resort to storing the passphrase for the key on disk (bad) the system's ssh agent could be leveraged.
phpseclib has an implementation for that.
I raised a related issue for laravel some (long) time ago which might contain useful information for that:
https://stackoverflow.com/a/23247161/580651
laravel/framework#4235
If i'm not mistaken this would also allow to omit passing the path to the key file when there is a ssh config file present that specifies which key to use on individual hosts.
Dear contributor,
because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.