im trying to connect my SFTP Server with privatekey.pem / privatekey.ppk But still getting same error which is "Could not login with username : XXXXX , host : XX.XX.XX.XX" [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/icMPx.png
Initially, i have privatekey.ppk then i convert to privatekey.pem using puttygen because i thought that Laravel cant use file .ppk . But the result still same.
btw , I can access through WinSCP with my privatekey.ppk and Terminal with my privatekey.pem . But unfortunately Laravel , i cannot get through.
Some info im using :
- Laravel 8
- Php 7
- league/flysystem-sftp: 1.1
- phpseclib/phpseclib: 2.0
I also have try phpseclib connection but still same
use phpseclib\Crypt\RSA;
use phpseclib\Net\SFTP;
$key = new RSA;
$key->loadKey(file_get_contents('C:/key/privatekey.pem'));
$sftp = new SFTP('XX.XX.XX.XX');
if (!$sftp->login('XXXXX', $key)) {
dd($sftp->getLog());
}
my config\filesystems.php
'sftp' => [
'driver' => 'sftp',
'host' => 'XX.XX.XX.XX',
'username' => 'XXXX',
'privateKey' => file_get_contents('C:/key/privatekey.pem'),
'root' => '/upload'
]
my myprivatekey.pem
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACAiSbn2URP33h/UjsByVXQA1H/sb8eNTf4PjPFlRdYp4gAAAJj7Xoxl+16M
ZQAAAAtzc2gtZWQyNTUxOQAAACAiSbn2URP33h/UjsByVXQA1H/sb8eNTf4PjPFlRdYp4g
-----END OPENSSH PRIVATE KEY-----
Hope somebody can give me some idea what's going on. thank you
Maybe problem is that privateKey in config should be path to file, not content.
I'm using SFTP in my app:
I followed this docs: https://laravel.com/docs/10.x/filesystem#sftp-driver-configuration
.env
filesystems.php
and i get files on that remote disk:
I hope that this can help.