# SSH keys

> For AI agents: the complete documentation index is at https://buddy.works/llms.txt

Learn how to upload and use SSH keys to authenticate deployment and script execution on remote servers.

SSH keys are one of the most secure and convenient authentication methods. A common use case involves, for example, cloning a repository locally or connecting to 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 server script execution in the SSH action
3. Authenticate the download of private modules and dependencies in container actions

You can add the key individually to each of your actions, but a more straightforward method is to add it as an environment 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 it 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 Variables, Keys & Assets tab in the left menu.
- **Project**: go to the Variables, Keys & Assets tab in the left menu.
- **Pipeline**: go to the pipeline that you want to use the key in and switch to the Variables tab.

![Adding SSH key as workspace environment variable](https://buddy.works/docs/faq/ssh-keys-in-actions/ssh-keys-in-actions-1.png)

## Using SSH keys

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

![Using SSH key as an environment variable in SFTP action](https://buddy.works/docs/faq/ssh-keys-in-actions/ssh-keys-in-actions-2.png)

2. In container actions, all defined keys are available in the `~/.ssh` directory of the pipeline filesystem:

- 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, for example:
 
```text
Host github.com
    IdentityFile ~/.ssh/github.key
```

![Pipeline filesystem view](https://buddy.works/docs/faq/ssh-keys-in-actions/ssh-keys-in-actions-3.png)


---
Original source: https://buddy.works/docs/pipelines/ssh-keys