Shan
Shan

Reputation: 2832

Connecting to EC2 using Php | RSA | PhpSec

The error I am getting is SSH_MSG_USERAUTH_FAILURE: publickey,gssapi-keyex,gssapi-with-mic

I logged via Putty and generated keys using the following steps

I used the below commands to generate a RSA key and copied the RSA key from there and storied it as id_rsa in a textfile with no extension (I didn't give any passphrases too)

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ec2_user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ec2_user/.ssh/id_rsa.

And here is my php code.when I try to execute it..it saves authentication failed always.Whether I am doing anything wrong here..?

 <?php
     include('Net/SSH2.php');
     include('Crypt/RSA.php');

     $rsa = new Crypt_RSA();
     $rsa->loadKey(file_get_contents('id_rsa'));
     $ssh = new Net_SSH2('ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com');
     if ($ssh->login('ec2_user', $rsa)) {
        echo "Public Key Authentication Successful\n<br />";
     } else {
         die('Public Key Authentication Failed');
  }

 echo $ssh->exec("pwd");
?>

Upvotes: 0

Views: 193

Answers (2)

neubert
neubert

Reputation: 16802

Usually, with AWS, the username is ec2-user - not ec2_user.

Upvotes: 2

nmallare
nmallare

Reputation: 97

Why aren't you using the .pem file (key pair) provided to you when you launched the instance?

Upvotes: 0

Related Questions