-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathttyd-login
More file actions
executable file
·31 lines (23 loc) · 828 Bytes
/
ttyd-login
File metadata and controls
executable file
·31 lines (23 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
set -e
script_name=$(basename "$0")
remote_addr="$1"
hostname=$(hostname)
error_pipe="${TMPDIR:-/tmp}/$script_name.$$.pipe"
error_log="${TMPDIR:-/tmp}/$script_name.$$.stderr"
cleanup() {
trap - TERM
rm -f -- "$error_pipe" "$error_log"
}
trap cleanup TERM EXIT
[ ! -z "$remote_addr" ] && echo "Connecting to $hostname from $remote_addr."
read -rp "$hostname login: " ssh_user
touch "$error_log"
mkfifo "$error_pipe"
tee -a "$error_log" < "$error_pipe" >&2 &
ssh -o PreferredAuthentications=password -l "$ssh_user" "$hostname" 2>"$error_pipe" || true
failures=$(grep -ic "too many authentication failures" "$error_log")
if [ $failures -gt 0 ] && [ ! -z "$remote_addr" ]; then
logger -p auth.err -t "$script_name" "error: maximum authentication attempts exceeded for $ssh_user from $remote_addr"
fi
sleep 3