Add SSH Keys
You can add SSH keys for use in connecting to remote servers, such as an AWS EC2 instance.
In this topic:
Before You Begin
Step 1: Configure SSH Connectivity
ssh-keygen -t rsa(
rsaspecifies SSHv2) and then follow the prompts to create the PEM key. Also, ensure that the
END RSAlines are included when you paste the key into Harness (
pbcopyis useful for copying the key). For more information, see the ssh-keygen man page.
For example, if you want to SSH into an EC2 instance, in a terminal, enter the following command:
ssh -i "example.pem" email@example.com
The SSH secret you add here can be used in Harness components wherever they need to SSH into your remote server. For example, in a Harness Environment Service Infrastructure/Infrastructure Definition dialog, you specify Connection Attributes that use the SSH secret to connect to the target host.
To add an SSH key that can be referenced in Harness entities, do the following:
- In Secrets Management, click SSH.
- Click Add SSH Key. The SSH Configuration dialog appears.
- Enter a Display Name for the SSH credentials.
- (Required.) In User Name, provide the user name for the user account on the remote server. For example, if you want to SSH into an AWS EC2 instance, the user name would be ec2-user.
- Do one of the following:
Do not open a .pem file in a text editor and copy and paste its contents into Inline SSH Key. Open a terminal, browse to the location of the .pem file, and use pbcopy to copy the contents of the file, like this:
- Click Inline SSH Key and paste in the key to use. Enter the private key file for the SSH connection.
$ cat example.pem | pbcopy. Next, click in the Inline SSH Key field and paste the contents.
- Click SSH KeyFile Path (on Delegate) and specify the location of the key. This is the file path on the server running the Harness Delegate, such as /home/johndoe/example.pem.
- Click Password and enter the password for the user account.
- In Passphrase, enter in the SSH key passphrase if one is required. It is not required by default for AWS or many other platforms.
- In SSH Port, leave the default 22 or enter in a different port if needed.
- If you want to restrict the use of these SSH credentials to specific Harness components, do the following:
- In Usage Scope, click the drop-down under Applications, and click the name of the application.
- In Environments, click the name of the environment.
Step 2: Test Host Connectivity
- Click TEST. The Host Connectivity Test tool appears.
- In Host Name, enter the host name of the remote server you want to SSH into. For example, if it is an AWS EC2 instance, it will be something like,
- Click RUN. If the test is unsuccessful, you might see an error stating that no Harness Delegate could reach the host, or that a credential is invalid. Ensure that your settings are correct and that a Harness Delegate is able to connect to the server.
- When a test is successful, click Submit.