How to Set Up SSH Deploy in CircleCI
add_ssh_keys loads a registered deploy key so a job can SSH or rsync to your host.
Register an SSH key in project settings, reference it by fingerprint with add_ssh_keys, and the agent can reach your server for an rsync or remote deploy command.
Deploy with a registered SSH key
Load the key, pin the host, then rsync the build to the server.
.circleci/config.yml
version: 2.1
jobs:
deploy:
docker:
- image: cimg/base:2024.01
steps:
- checkout
- add_ssh_keys:
fingerprints:
- "SO:ME:FI:NG:ER:PR:IN:T"
- run: ssh-keyscan -H "${DEPLOY_HOST}" >> ~/.ssh/known_hosts
- run: rsync -az ./dist/ deploy@${DEPLOY_HOST}:/var/www/app/
workflows:
ship:
jobs:
- deployNotes
- ssh-keyscan pins the host key so the deploy does not stall on an interactive prompt.
- Scope the deploy key to a single server and rotate it if a build environment is compromised.