From e68758043b5c49ff9b9f28c14a7000952bf2c246 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 14 Sep 2024 00:48:22 -0400 Subject: [PATCH] feat: add support for setting an ssh passphrase to use for ssh commands Closes #116 --- README.md | 4 ++++ bin/setup-ssh | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 598c649..831d2d7 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,10 @@ The following environment variables are supported: - `SSH_PRIVATE_KEY`: - description: A private SSH key that has push acces to your Dokku instance - required: true +- `SSH_PASSPHRASE`: + - description: If set, the passphrase to use when interacting with an SSH key that has a passphrase + - required: false + - default: '' - `TRACE`: - description: Allows users to debug what the action is performing by enabling shell trace mode - required: false diff --git a/bin/setup-ssh b/bin/setup-ssh index f711bbd..675edf7 100755 --- a/bin/setup-ssh +++ b/bin/setup-ssh @@ -38,6 +38,14 @@ else chmod 600 "/root/.ssh/known_hosts" fi +if [ -n "$SSH_PASSPRHASE" ]; then + export SSH_ASKPASS="/root/.ssh/askpass.sh" + export SSH_ASKPASS_REQUIRE=force + # shellcheck disable=SC2016 + printf '#!/bin/sh\necho "$SSH_PASSPRHASE"\n' >"$SSH_ASKPASS" + chmod +x "$SSH_ASKPASS" +fi + log-info "Adding SSH Key to ssh-agent" eval "$(ssh-agent -s)" ssh-add /root/.ssh/id_rsa