blob: 368695942dc1acd7137977d375948a25be1b73e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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)"
# Check passphase, or exit 0
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
|