PHP AWS Host Key verification failed

Viewed 65

I have a AWS EC2 instance. I am trying to connect to the instance from a local machine using php. I have already installed awscli, aws-sdk-php, configured aws cli with access keys and secret keys. Besides, I have created a config.php to include the access keys and secret keys. I am using a .pem file to connect to the ec2 instance. The .pem file has 400 permission and is owned by www-data:www-data and it is residing inside /var/www/html folder.

Through a php script I am initiating the instance. The ec2 instance gets initiated. As a next step, I am trying to run a bash script through PHP. The code for the same is as follows:

ssh -i mypem.pem ubuntu@$ipaddress "bash /home/ubuntu/checkWorkingDir.sh $dirName"

While the EC2 gets started by php, the program gets stuck here and I am getting a message

Host Key Verification Failed.

I am able to log into EC2 through ssh manually by using the same .pem file from a different folder using:

ssh -i mypem.pem ubuntu@ip_address -- this is working

the pem file in the /var/www/html folder lists like this:

-r-------- 1 www-data www-data 1692 Jan 10 16:39 mypem.pem

I have created a same set up in my laptop and everything works fine. In what all other ways I could read this problem of Host key verification failed message.

0 Answers
Related