From f088054eca2e4f3622bef03b288d38e38e5f9131 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 24 Nov 2024 04:55:07 +0000 Subject: Update --- bin/mail/append_authorized_key.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 bin/mail/append_authorized_key.sh (limited to 'bin/mail/append_authorized_key.sh') 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 @@ +#! /bin/bash + +# Append last line of mail into ~/.ssh/authorized_keys +# Usage: +# 1. put this file into ~/.forward +# 2. send mail with header "Passphase: ", and value in ~/.config/passphase +# 3. try ssh + +# Restore mail in variable +MAIL="$(cat)" + +# Get user passphase +test -f ~/.config/passphase || exit 1 +PASSPHASE="$(cat ~/.config/passphase)" + +# Only execute the following script when header matched +grep -qE "^Passphase: ${PASSPHASE}" <<<"$MAIL" || exit 0 + +# Append comment and last line to ~/.ssh/authorized_keys +exec 1>>~/.ssh/authorized_keys +<<<"$MAIL" grep 'From:' | head -1 | sed 's/^/# /' +<<<"$MAIL" sed -En '/^.+/p' | tail -1 -- cgit v1.2.3-70-g09d2