Knowledge

How to use SSH keys in actions?

SSH keys are one of the most secure and convenient authentication methods. A common use case can be cloning a repository locally or connecting with a remote server. In Buddy's pipelines you can use the keys for the following things:

  1. Authenticate file upload in the SFTP action
  2. Authenticate script execution on the server in the SSH action
  3. Authenticate the download of private modules and dependencies in build actions

You can add the key individually to each of your actions, but an easier method is to add it as an environmental variable that can be used in the input fields across the whole workspace.


Defining SSH keys

To use a key in one of the actions, you need to add them to environment variables by entering the ${KEY_NAME} and value. You can define keys for the whole workspace, a project or a single pipeline:

  • Workspace: go to the workspace Preferences and switch to the Environment Variables tab.
  • Project: go to Project Options and click Environment Variables in the right column.
  • Pipeline: go the pipeline that you want to use the key in and click Environment Variables in the right column.
Adding SSH key as workspace environment variable
Adding SSH key as workspace environment variable

Using SSH keys

  1. To use the key in an SFTP or SSH action, just provide the key value in the key input:

    Using SSH key as environment variable in SFTP action
    Using SSH key as environment variable in SFTP action
  2. In build actions all defined keys are available in the ~/.ssh directory.

    • If you want Buddy to use your key in SSH connections by default, name it id_rsa
    • If your build requires more than one key, add ~/.ssh/config to the pipeline's filesystem and define which key is used for what host, eg.:

      Host github.com
          IdentityFile ~/.ssh/github.key
      
    Location of pipeline filesystem
    Location of pipeline filesystem

Get started now

14 days of unlimited trial. No credit card required.