Skip to content

Commit

Permalink
Merge pull request #3 from Burnett01/feat/support-key-with-passphrase
Browse files Browse the repository at this point in the history
feat: Add support for SSH keys with passphrases.
  • Loading branch information
JoshPiper authored Aug 2, 2021
2 parents 82fd3df + 39550df commit dae5b34
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dockerfile
LICENSE
*.md
.git*
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ RUN rm -rf /var/cache/apk/*
RUN mkdir ~/.ssh

# Copy in our executables.
COPY agent-start agent-stop agent-add agent-autostart /bin/
COPY hosts-clear hosts-add /bin/
COPY agent-* hosts-* /bin/
RUN chmod +x /bin/agent-* /bin/hosts-*

# Prepare for known hosts.
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ It takes one optional argument, for the name of the agent to be stopped. Default
#### agent-add
This command adds a key to the currently running SSH agent. The key is taken from stdin, and the agent used is that in SSH_AGENT_PID.

#### agent-autoadd
#### agent-autostart
This command starts the SSH agent and loads the private key from the "SSH_PRIVATE_KEY" environment var. The command takes one optional argument, for the name of the agent to be started. Defaults to "default".
As with agent-start, this command needs to be sourced.

#### agent-askpass
This command is called by ssh-add when the [SSH_ASKPASS](https://man.openbsd.org/ssh-add.1#ENVIRONMENT) variable is set active. The command returns the SSH_PASS to [ssh-askpass(1)](https://man.openbsd.org/ssh-askpass.1).

This command is ignored by ssh-add if the key does not require a passphrase.

### known_hosts management
#### hosts-clear
This command truncates the known_hosts file and sets its permissions.
Expand Down Expand Up @@ -78,3 +83,11 @@ deploy:
script:
- rsync -zrSlhaO --chmod=D2775,F664 --delete-after . $FTP_USER@$FTP_HOST:/var/www/deployment/
```

## Using with passphrase protected key

You can supply a passphrase with ``SSH_PASS`` to ``agent-add``, ``agent-start`` or ``agent-autostart``.

```
SSH_PASS="THE_PASSPHRASE" agent-add
```
2 changes: 1 addition & 1 deletion agent-add
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

source agent-start "${1:-default}"
cat - | tr -d '\r' | ssh-add - >/dev/null
cat - | tr -d '\r' | DISPLAY=1 SSH_ASKPASS=agent-askpass ssh-add - >/dev/null
2 changes: 2 additions & 0 deletions agent-askpass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "$SSH_PASS"

0 comments on commit dae5b34

Please sign in to comment.