Skip to content

Instantly share code, notes, and snippets.

@brettfreer
Created June 3, 2016 00:49
Show Gist options
  • Save brettfreer/ab40f1c33923039e003bf2194c15a53d to your computer and use it in GitHub Desktop.
Save brettfreer/ab40f1c33923039e003bf2194c15a53d to your computer and use it in GitHub Desktop.
Expire/delete inactive linux user accounts
#!/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