I have a bash script inside a Docker container that needs to access remote server via ssh. I have SSH key inside a variable. How can I add it to SSH?
I have a bash script inside a Docker container that needs to access remote server via ssh. I have SSH key inside a variable. How can I add it to SSH?
If you are using Gitlab CI/CD and you want to use a variable as an SSH key you can do the following:
Settings -> CI/CD -> VariablesUse that variable in your .gitlab-ci.yml file:
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
Also, you can use:
echo "${SSH_PRIVATE_KEY}" | ssh-add -
or
ssh-add <(echo "$SSH_PRIVATE_KEY")