Have 3 servers: Local, Bare, Development.
The following workflow works perfectly:
1. Make my local changes
2. git push to Bare
3. ssh into Bare
4. $ ssh ip.of.Development.server "cd /path/to/Development/repo; git pull"
This does exactly what you would expect, content gets pulled to my Development server, displays on the page, all is well.
However, if I move the last line to my hooks/post-receive file on Bare, I get a
remote: Host key verification failed.
I can ssh from Development to Bare without issue and without using a password (after I set up an RSA pair).
Even if I cut the post-receive hook down to just
ssh ip.of.Development.server
I get the same error, but if I enter this exact same line on the command line, it works fine.
Best Answer
Inside the "bare" server you should edit the ~/.ssh/known_hosts file of the user that's running the hook.
Example of a line of ~/.ssh/known_hosts:
You should remove the line that identifies the server that you're trying to connect to and then, BEFORE launching again your script, do a "ssh user@destination" with your user so that the destination server's host key to your known_hosts file. Like this: