diff options
Diffstat (limited to 'bin/mail')
-rwxr-xr-x | bin/mail/append_authorized_key.sh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bin/mail/append_authorized_key.sh b/bin/mail/append_authorized_key.sh new file mode 100755 index 0000000..950be90 --- /dev/null +++ b/bin/mail/append_authorized_key.sh | |||
@@ -0,0 +1,22 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | # Append last line of mail into ~/.ssh/authorized_keys | ||
4 | # Usage: | ||
5 | # 1. put this file into ~/.forward | ||
6 | # 2. send mail with header "Passphase: ", and value in ~/.config/passphase | ||
7 | # 3. try ssh | ||
8 | |||
9 | # Restore mail in variable | ||
10 | MAIL="$(cat)" | ||
11 | |||
12 | # Get user passphase | ||
13 | test -f ~/.config/passphase || exit 1 | ||
14 | PASSPHASE="$(cat ~/.config/passphase)" | ||
15 | |||
16 | # Only execute the following script when header matched | ||
17 | grep -qE "^Passphase: ${PASSPHASE}" <<<"$MAIL" || exit 0 | ||
18 | |||
19 | # Append comment and last line to ~/.ssh/authorized_keys | ||
20 | exec 1>>~/.ssh/authorized_keys | ||
21 | <<<"$MAIL" grep 'From:' | head -1 | sed 's/^/# /' | ||
22 | <<<"$MAIL" sed -En '/^.+/p' | tail -1 | ||