diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2024-11-24 12:55:07 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2024-11-24 12:55:07 +0800 |
| commit | f088054eca2e4f3622bef03b288d38e38e5f9131 (patch) | |
| tree | 166604263a09fc1385bd3f3a57e2370ceaeafea9 /bin/mail | |
| parent | fb636ba27271bfbaacdcceac5c5aaae93a840191 (diff) | |
Update
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 | ||