Skip to content

Instantly share code, notes, and snippets.

@christopher-hopper
Last active December 20, 2015 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopher-hopper/6118414 to your computer and use it in GitHub Desktop.
Save christopher-hopper/6118414 to your computer and use it in GitHub Desktop.
Kill the processes and back-up accounts before removing

Remove Linux user accounts

I killed the processes and backed-up old accounts on the Peregrine UAT server 10.3.28.44. You can find tarballs for the home folders of all removed accounts on Peregrine UAT at:

10.3.28.44:/root/bak/deleted/users

To remove accounts safely I did the following:

  1. Lock the account.

    # passwd -l username
    
  2. Backup the home folder.

    # tar -zcvf /root/bak/deleted/users/username.$(id -u username).$(date +%Y%m%d%H%M%S).tar.gz /home/username/
    
  3. Check if the user has running processes and if so kill them .

    # PROCS="$(pgrep -d, -u username 2>/dev/null)"; if [ -n "$PROCS" ]; then ps -fp $PROCS; else echo "No processes running" 1>&2; fi
    # killall -KILL -user username 
    
  4. Remove the user and its home folder.

    # userdel -r username
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment