Mounting a volume for ssh keys

Hey guys, complete drone noob here and I was hoping to get some help with my pipeline.

I have a step that involves ssh-ing into a server in order to run some bash scripts. I read somewhere online that it might be a good idea to mount the volume where the ssh keys live, and then execute my commands. I can’t for the life of me get it to work!

In the step, it’s mounted as:
- name: ssh-keys
path: /ssh

And in the ‘volumes’ section, i have it as:

  • name: ssh-keys
    path: /home/drone/.ssh

When i do a “ls -a” as part of my step just to see if it’s mounted, i see no ‘ssh’ folder. Is there a step I’m missing here?

1 Like

The recommended approach is to use secrets. See How can I set host ssh key?.

Is there a format to the ssh key when it’s added to the secrets? I’m getting a “Host key verification failed” error when running my step.

I’ve ssh’d from the machine where i copied the key from and it’s able to do so, but when i use it for the step, i get that error

Nope, the example I linked to is confirmed to work. However, maybe you need to add the host to the ssh known_hosts list? For example

  - name: fetch
    image: golang
      # write the ssh key to disk
      - mkdir /root/.ssh
      - echo -n "$SSH_KEY" > /root/.ssh/id_rsa
      - chmod 600 /root/.ssh/id_rsa

      # add github to known hosts
      - touch /root/.ssh/known_hosts
      - chmod 600 /root/.ssh/known_hosts
      - ssh-keyscan -H > /etc/ssh/ssh_known_hosts 2> /dev/null