Laravel Flysystem sftp Permission Denied

Viewed 5618

Im trying to use the Laravel Flysystem with the sftp adaptor from PHP League (league/flysystem-sftp). Using Laravel 5.4 and version 3.7 of the Flysystem.

When I attempt to put a file on the server, i get the message:

Cannot connect to someadress.com:22. Error 13. Permission denied

Here is the code:

$box = new Filesystem(new SftpAdapter(Config::get('flysystem.connections.sftp')));
$box->put('test.txt', 'bar');

and the connection details from the config:

'sftp' => [
     'driver'     => 'sftp',
     'host'       => 'someadress.com',
     'port'       => 22,
     'username'   => 'someuser',
     'password'   => 'ArndomPa55',
     'privateKey' => '/home/user/.ssh/id_rsa',
     'root'       => '/var/www/html/site/box/',
     'timeout'    => 20,
 ],

When I make an SSH connection from the server where this is running, it connects fine, without a password prompt, so it is using the Private Key. So not sure why this isn't working.

I've checked the secure log on the receiving server and nothing is in there.

3 Answers

While extremely old, and I am committing necromancy here, I came across this issue and none of these fixes helped. What happened (and may happen to others) is that the key type was openssh not rsa and the call to ssh2::_privatekey_login returned false, causing the whole event to fail. If your key is openssh (identified by -----BEGIN OPENSSH PRIVATE KEY----- as the header), run the following to convert it to RSA, fixing the problem.

ssh-keygen -p -m PEM -f [filename here]

I have a similar problem. The exception was :

local.ERROR: LogicException: Could not login with username: username, host: xx.xx.xx.xx. 

Following code in vendor\league\flysystem-sftp\src\SftpAdapter i found that hostFingerprint always returned null. After that I just removed privateKey => 'path/to/key' from the configuration for example

'sftp' => [
     'driver'     => 'sftp',
     'host'       => 'someadress.com',
     'port'       => 22,
     'username'   => 'someuser',
     'password'   => 'ArndomPa55',
     //'privateKey' => '/home/user/.ssh/id_rsa',
     'root'       => '/var/www/html/site/box/',
     'timeout'    => 20,
 ]

, and i connected to the server. I think it has to do something with the servers sftp configuration. For now that suites me for testing my scripts but i will look for the reason.

I hope that helps finding a permanent solution.

I had the same problem. I have changed the user actually do php execution to the user writed sftp configuration. It was working on php-fpm. I have changed user & group on php-pfm confguration. I have not changed http.conf It works!

Related