I'm trying to connect my EC2 instance with ssh2 php module.
I've obtained the public key from known_hosts file (format: "ssh-rsa XXXX..." putted into "public.txt" file) and i'm using the amazon keypair.pem as private key ("-----BEGIN RSA PRIVATE KEY----- XXXX..." in private.pem).
I'm using this php code:
$connection = ssh2_connect('XXXX.eu-west-1.compute.amazonaws.com', 22, array('hostkey'=>'ssh-rsa'));
if(!ssh2_auth_pubkey_file(
$connection,
'ubuntu',
'public.txt',
'private.pem'
))
die("Auth error");
$sftp = ssh2_sftp($connection);
The error i get is: ssh2_auth_pubkey_file(): Authentication failed for ubuntu using public key: Username/PublicKey combination invalid
What am i doing wrong?