I am trying to clone a git repository while my EC2 instance boots up. Following is the code I have till now:
echo "$ssh_key" | sed -e 's/^"//' -e 's/"$//' > /home/ubuntu/.ssh/id_rsa
chmod 400 /home/ubuntu/.ssh/id_rsa
eval `ssh-agent -s`
ssh-add /home/ubuntu/.ssh/id_rsa
git clone git@github.com:xyz.git
But the code always fails while cloning the repository. Following is the error I get:
Agent pid 2398
Identity added: /home/ubuntu/.ssh/id_rsa (/home/ubuntu/.ssh/id_rsa)
Cloning into 'test-folder'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
How to do I get around this? The keys are proper, and I am able to clone the repository when I manually run the command from the cli, but fails in userdata of EC2