Start Building for Free
CircleCI.comAcademyBlogCommunitySupport

Deploy over SSH

5 days ago1 min read
Cloud
Server v4.x
Server v3.x
Server v2.x

To configure CircleCI to deploy your application over SSH, follow the steps below.

  1. Add the SSH key for the server to which you’re deploying. For instructions, see the Adding an SSH Key to CircleCI document.

  2. Add the SSH username and SSH hostname of your build VM as environment variables. For instructions, see the Set an environment variable in a project documentation. In this example, these variables are defined as SSH_USER and SSH_HOST, respectively.

  3. In your .circleci/config.yml, create a deploy job and add a command to deploy the main branch.

    version: 2
    
    jobs:
        build:
        #...
        deploy:
        machine:
            enabled: true
        steps:
            - run:
                name: Deploy Over SSH
                command: |
                ssh $SSH_USER@$SSH_HOST "<remote deploy command>"
    
    workflows:
        version: 2
        build-and-deploy:
        jobs:
            - build
            - deploy:
                requires:
                - build # only deploy once build job has completed
                filters:
                branches:
                    only: main # only deploy on the main branch

Help make this document better

This guide, as well as the rest of our docs, are open source and available on GitHub. We welcome your contributions.

Need support?

Our support engineers are available to help with service issues, billing, or account related questions, and can help troubleshoot build configurations. Contact our support engineers by opening a ticket.

You can also visit our support site to find support articles, community forums, and training resources.