Skip to content

Instantly share code, notes, and snippets.

@jamesandariese
Created August 24, 2015 21:58
Show Gist options
  • Save jamesandariese/7f06fe51add2441946a2 to your computer and use it in GitHub Desktop.
Save jamesandariese/7f06fe51add2441946a2 to your computer and use it in GitHub Desktop.
Iterate over possibly enabled users on remote host
#!/bin/sh
ssh -l root "$1" awk -F: "'\$2 ~ /^[^!*]/ {print \$1}'" /etc/shadow
for f in `ssh -l root "$1" cat /etc/passwd | cut -d ':' -f 1,6`;do
if ssh -l root "$1" [ -e "${f#*:}/.ssh/authorized_keys" ];then
echo "${f%:*}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment