Created
June 3, 2016 00:49
-
-
Save brettfreer/ab40f1c33923039e003bf2194c15a53d to your computer and use it in GitHub Desktop.
Expire/delete inactive linux user accounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Expire and delete inactive linux users | |
# | |
# check this before running! | |
exclude_users="keepme|metoo|daemon|adm|lp|sync|shutdown|halt|mail|news|uucp|operator|man|postmaster|smmsp|portage|nobody|sshd|cron|ntp|messagebus|mysql|apache|haldaemon|ftp|postfix|dhcp|ntop|fetchmail|squid|hsqldb|tomcat" | |
remove_period="548" # 18 months | |
main() | |
{ | |
lastlog -b ${remove_period} | egrep -v ${exclude_users} | while read line | |
do | |
set $line | |
user_id=${1} | |
echo "Remove ${user_id}" | |
/usr/sbin/userdel -f -r ${user_id} | |
done | |
} | |
main | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment