summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon GECOS <u@adam>2021-03-03 20:51:43 -0500
committerGordon GECOS <u@adam>2021-03-03 20:51:43 -0500
commit1ab3ef99a3d24dd8470eb56845c66e870fc9560d (patch)
treea1b59b1075e3da0efb76860bad8c56f15e585e67
penme: open the root account to everyone on the LAN
-rwxr-xr-xpenme36
1 files changed, 36 insertions, 0 deletions
diff --git a/penme b/penme
new file mode 100755
index 0000000..06356ab
--- /dev/null
+++ b/penme
@@ -0,0 +1,36 @@
1#!/bin/sh
2if [ "$(id -u)" -ne 0 ]
3then
4 exec sudo -- "$0" "$@"
5fi
6
7scan_network()
8{
9 ip -oneline addr |
10 sed -ne 's/.*inet \([^ ]*\) .*/\1/p' |
11 while read line
12 do
13 case "$line" in
14 127.*) continue ;;
15 esac
16 arp-scan "$line" 2>/dev/null
17 done | while read ip junk
18 do
19 case "$ip" in
20 *.*.*.*) echo $ip ;;
21 *) continue ;;
22 esac
23 done
24}
25
26ips=$(scan_network)
27
28mkdir -p /root/.ssh
29touch /root/.ssh/authorized_keys
30
31ssh-keyscan - $ips | while read ip key
32do
33 line=$(printf '%s host key @ %s\n' "$key" "$ip")
34 grep -Fx "$line" /root/.ssh/authorized_keys ||
35 echo "$line" >> /root/.ssh/authorized_keys
36done