I'm using a startup-script on Google Cloud Compute.
The goal of the script is to clone a private repo from Github at startup time of the compute server.
To authenticate, I have a public deploy key for this one repo. The private deploy key passed to the script at startup time.
... # Some action where the private key is passed in
chmod u=rw,go= github_pri_deploy_key
eval "$(ssh-agent -s)" # Start ssh-agent in the background
ssh-add ${WORKING_DIR_PATH}/github_pri_deploy_key
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
The issue I'm running into is the /root/.ssh/known_hosts
file is inaccessible during startup time.
So I get an error in the logs saying Host key validation failed.
What I tried
I've tried attempting creating the file manually but same issue since the root user couldn't create the file.
I was able to get the desired result of adding the Host key when after the machine starts up and I ssh into the machine and perform the task manually.
My startup-script
is run as root, as is the only option on GCP Compute. But if it's running as root, why can't ssh-keyscan append to the /root/ file?
This is the best I can illustrate since the repo is private. Thank you.