← Greg Troszak's Notes

SSH key ordering matters in Sourcehut builds

This is mostly relevant for private repos, which require a dedicated SSH key for cloning.

When a Sourcehut build uses multiple SSH key secrets, SSH tries them in order. Put the key needed for cloning first, and pass -i ~/.ssh/<UUID> to specify the right key for other SSH operations like rsync.

Also make sure to use the SSH clone URL.

Here's an example.

image: alpine/edge
packages:
  - openssh
  - rsync
  - zola
secrets:
  - ec118555-3160-4f91-90ed-99af094cb93f
  - 613df8e9-5ed2-4c2c-82aa-4b056feef5ff
environment:
  deploy_user: greg
  deploy_host: gregtroszak.me
  deploy_path: /var/www/notes.gregtroszak.me
sources:
  - git@git.sr.ht:~gtroszak/notes
tasks:
  - build: |
      cd notes
      zola build
  - deploy: |
      ssh-keyscan $deploy_host >> ~/.ssh/known_hosts
      rsync -avz --delete \
        -e "ssh -i ~/.ssh/613df8e9-5ed2-4c2c-82aa-4b056feef5ff" \
        notes/site/ \
        $deploy_user@$deploy_host:$deploy_path/

Resources