Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Host verification failed error when running git clone inside dockerfile on AWS EC2 instance as host and a private git repository

I am using AWS ec2 instance as private git repository. This instance is also used for running Dockerfile and docker file tries to checkout code from this private repository. My basic setup is done as per https://alvinabad.wordpress.com/2013/03/23/how-to-specify-an-ssh-key-file-with-the-git-command/ option 2. However, when i am running my docker build command:

$ sudo docker build -t "spring-petclinic" .

The build script stops at line:

RUN /root/.ssh/git.sh -i /root/.ssh/.pem clone [email protected]:/usr/local/git-repos/spring-petclinic.git

and gets following error:

"Cloning into 'spring-petclinic'... Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists."

I have search through google for this type of error, on similar kind of setup, but unable to search for.

Please help!!!

Thanks

like image 740
munish Avatar asked Jan 28 '15 06:01

munish


People also ask

How do I fix host key verification failed SSH?

To fix this error, we need to delete the offending key from the “known_hosts” file present in our system in “. ssh” directory. The error gives you the remote server's IP address and the line number on which the key is stored in the “known_hosts” file.

Could not read from remote repository make sure you have the correct access rights?

The Git “fatal: Could not read from remote repository” error occurs when there is an issue authenticating with a Git repository. This is common if you have incorrectly set up SSH authentication. To solve this error, make sure your SSH key is in your keychain and you connecting to a repository using the correct URL.


1 Answers

The problem that you're seeing is that it's connecting for the first time to an unknown host and SSH plays it safe by default. If you were running the command interactively, you'd get prompted to add the key to your known_hosts file.

You can either add the host key to the known_hosts file (better) or set StrictHostKeyChecking to no in the ssh config (worse).

like image 102
Nathaniel Waisbrot Avatar answered Sep 28 '22 04:09

Nathaniel Waisbrot