I've been trying out phpseclib, to run a simple SSH session to various cloud servers. Each time using key login.
A test with key that has no password protection is fine: I tried one on standard port 22, then another on a non-standard port, and both worked. (Both are on Amazon EC2, different regions.)
But the first test I tried failed, with:
SSH_MSG_USERAUTH_FAILURE: publickey,password
It has a password-protected key, with a non-standard port. Here is my script (with names changed to protect the innocent):
include('Net/SSH2.php');
include('Crypt/RSA.php');
$ssh = new Net_SSH2('10.1.2.3', /*port*/999);
$key = new Crypt_RSA();
$key->setPassword('secrets');
$ret = $key->loadKey(file_get_contents('/home/tester/.ssh/my_private_key'));
if(!$ret){
echo "loadKey failed\n";
exit;
}
if (!$ssh->login('ubuntu', $key)) {
print_r($ssh->errors);
exit("Login Failed\n");
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
I did ssh-agent -d /home/tester/.ssh/my_private_key (to force it to prompt me), then used ssh on the commandline, and it worked. And if I skip setting a password, the loadKey() returns false.
So, now I'm wondering if the type of key is not supported? The "bad" key starts like this:
-----BEGIN DSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,A541E5B6B9077483BCEF845
YMMV4.....
whereas the "good" keys start with:
-----BEGIN RSA PRIVATE KEY-----
YMMVgIBab54...
I found this question where the Proc-Type and DEK-Info appear to be fine, but his is RSA, not DSA. So is DSA the problem? (But if so, shouldn't phpseclib have complained when I tried to do loadKey()?)
Any suggestions about how I can get more information on the problem? (Without posting the actual keys here!)