Trying Everything to SSH but still "Host key verification failed."

I’m trying to follow this tutorial mainly, but I can never get logged into my remote machine:

https://tonyblyler.com/post/CI-Rsync-Deployment/

I’ve added the ssh host key and private key variables and I’ve added the public key to the authorized keys on my remote machine. This is the script I’m using:

task1:
  script:

  # Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
  - echo "${SSH_PRIVATE_KEY}" > id_rsa
  - chmod 700 id_rsa
  - mkdir "${HOME}/.ssh"
  - echo "${SSH_HOST_KEY}" > "${HOME}/.ssh/known_hosts"
  - ssh -T root@myIP

Are the paths wrong for the ssh key? This article says to use the ssh agent and I’ve tried that and I get the same error: https://docs.gitlab.com/ee/ci/ssh_keys/README.html

Do I need to get a different docker image? I’m using a shared runner.

Thanks for any help.

What error are you getting when you try to run this? Maybe there’s no SSH client in the Docker container you’re using?

I was getting “Host key verification failed” but it turns out I needed to fix the format of my known hosts key. I thought the known hosts key was the public key of the machine you are trying to SSH into, but it has it’s own format. I’m getting a new error which is:

mesg: ttyname failed: Inappropriate ioctl for device

I get this error after the ssh script successfully logs in, but then it exits after that error.

Most google search results say “mesg: ttyname failed: Inappropriate ioctl for device” is a result of a vagrant connection configuration error. I’m thinking it has something to do with how the network is mapped to the shared runner?

I finally figured out you can’t do a normal ssh command via these CI style yaml scripts unless you use something like an ‘expect’ shell script so most people just do a build and then copy via rsync or ssh which makes restarting a node server tough. You can however put pm2 on watch directory mode so it will reload after a change is made to a directory. Most of these CI people are still using old school apache or ruby so it’s not so easy to figure out how to do modern node yet. It would be easier if the CI was set up to just run bash commands on a remote server via ssh. Everyone already knows what their build process is in bash without yaml.