I’m trying to connect to a SSH2 server through SFTP in PHP using PHPSecLib. But my problem is that, the server requires a key file that is password protected but also username and password. It seems like that it’s only possible to provide either username + password or username + keyfile (optionally password protected).
How can I sign on using all these things?
http://phpseclib.sourceforge.net/
My code looks as
$key = new Crypt_RSA();
$key->setPassword('keypwd');
$key->loadKey(file_get_contents('ssh_file.ppk'));
$sftp = new Net_SFTP('hostname', 22);
if (!$sftp->login('username', $key))
echo 'Failed';
else
echo 'Success';
But where should I put ‘password’?
— Edit: The server only requires the RSA key, but somehow the key is not loaded properly
There is an example specifying how to load a password protected key file on the phpseclib website. Note the line
$key->setPassword('whatever');Keep in mind you’re not sending the password to the server. You just need the password in order to successfully load the key file. Then the username and key are sent to the server to authenticate you.