Add SSH key from variable
Also, you can use:
echo "${SSH_PRIVATE_KEY}" | ssh-add -
orssh-add <(echo "$SSH_PRIVATE_KEY")
ssh-add - <<< "${SSH_PRIVATE_KEY}"
If you are using Gitlab CI/CD and you want to use a variable as an SSH key you can do the following:
- Add your variable in
Settings
->CI/CD
->Variables
Use that variable in your
.gitlab-ci.yml
file:- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
Gitlab documentation