diff options
author | Gordon GECOS <u@adam> | 2021-03-03 20:51:43 -0500 |
---|---|---|
committer | Gordon GECOS <u@adam> | 2021-03-03 20:51:43 -0500 |
commit | 1ab3ef99a3d24dd8470eb56845c66e870fc9560d (patch) | |
tree | a1b59b1075e3da0efb76860bad8c56f15e585e67 |
penme: open the root account to everyone on the LAN
-rwxr-xr-x | penme | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,36 @@ | |||
1 | #!/bin/sh | ||
2 | if [ "$(id -u)" -ne 0 ] | ||
3 | then | ||
4 | exec sudo -- "$0" "$@" | ||
5 | fi | ||
6 | |||
7 | scan_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 | |||
26 | ips=$(scan_network) | ||
27 | |||
28 | mkdir -p /root/.ssh | ||
29 | touch /root/.ssh/authorized_keys | ||
30 | |||
31 | ssh-keyscan - $ips | while read ip key | ||
32 | do | ||
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 | ||
36 | done | ||