Project

General

Profile

Download (837 Bytes) Statistics
| Branch: | Revision:
1
#!/bin/bash
2
#
3
# lists the names of all ssh public keys in the authorized_key files of all general users and of root
4
#
5

    
6
_l="/etc/login.defs"
7
_p="/etc/passwd"
8
 
9
## get mini UID limit ##
10
l=$(grep "^UID_MIN" $_l)
11
 
12
## get max UID limit ##
13
l1=$(grep "^UID_MAX" $_l)
14
 
15
## use awk to print if UID >= $MIN and UID <= $MAX and shell is not /sbin/nologin   ##
16
users=(`awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max  && $7 != "/sbin/nologin" ) print $0 }' "$_p" | sed -r 's/^([[:alnum:]]*).*/\1/g'`)
17
cnt=${#users[@]}
18
users[$cnt]="root"
19

    
20
for u in "${users[@]}"
21
do
22
 home_dir=$(echo "echo ~$u" | bash)
23
 if [[ -r $home_dir/.ssh/authorized_keys ]]
24
  then
25
    echo "general user '$u'" 
26
    cat $home_dir/.ssh/authorized_keys  | sed -r "s/^([[:alnum:][:punct:]]*) [[:alnum:][:punct:]]* (.*)/  \1: \2/g"
27
  fi
28
done
29
 
(1-1/2)