Skip to content

Commit 3c1b5f4

Browse files
author
Vladislav Navrocky
committed
Added load ssh private key tool
1 parent f2935a0 commit 3c1b5f4

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ RUN apk add bash git curl sshpass openssh-client gettext && \
44
curl -sSL https://raw.githubusercontent.com/tests-always-included/mo/c86fd9a89b14471d1a4e3cdfd2c4483a26f89379/mo -o /usr/local/bin/mo && \
55
chmod +x /usr/local/bin/mo
66

7+
COPY load_ssh_private_key /usr/local/bin

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,21 @@ Features:
1010
* mo (mustache templates written in bash https://github.com/tests-always-included/mo)
1111
* sshpass
1212
* openssh-client
13+
* load_ssh_private_key
1314

1415
This image can be usefull in Gitlab CI where impossible to prepare and cache docker image for builds.
16+
17+
## load_ssh_private_key tool
18+
19+
Loads provided SSH private key with `ssh-agent`. This tool is useful for deploying artifacts to the remote host with `ssh`.
20+
21+
Usage:
22+
```
23+
load_ssh_private_key ${SSH_PRIVATE_KEY}
24+
```
25+
26+
or
27+
```
28+
export SSH_PRIVATE_KEY="xxx"
29+
load_ssh_private_key
30+
```

load_ssh_private_key

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
SSH_PRIVATE_KEY=${SSH_PRIVATE_KEY:-$1}
4+
5+
if [ -z "${SSH_PRIVATE_KEY}" ]; then
6+
echo "Usage: load_ssh_private_key <SSH_PRIVATE_KEY>"
7+
exit 1
8+
fi
9+
10+
eval $(ssh-agent -s)
11+
echo "${SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
12+
mkdir -p ~/.ssh
13+
chmod 700 ~/.ssh
14+
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

0 commit comments

Comments
 (0)