Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

userdel

Delete a user account, and with -r also its home folder and mail.

Niveau
RHCSA-examen
Groep
Gebruikers en groepen
Root nodig
Ja
Pakket
shadow-utils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

userdel removes the user from the account files, and the private group of the user if no other user has it as primary group.

Without -r the home folder stays. Files of the user in other places always stay: they then show a number instead of a name as owner. A new user with the same UID would own them, so find and clean them first.

Zo schrijf je het

userdel [OPTION]... LOGIN

Opties 6

Meest gebruikt

-r, --remove
Also remove the home folder and the mail spool.
-f, --force
Remove even when the user is logged in, and remove the group even if it is the primary group of another user. Dangerous.
-Z, --selinux-user
Remove the SELinux user mapping of the login.
-R, --root DIR
Work in this chroot folder.
-P, --prefix DIR
Use the files under this prefix folder.
-h, --help
Show help.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Delete a user and the home folder

    userdel -r contractor1

    The usual way for a lab or a test account.

  2. 2Delete only the account

    userdel olduser

    The files in /home/olduser stay (for a backup).

  3. 3Find files of a user before you delete it

    find / -xdev -user olduser 2>/dev/null

    Keep or move important files first.

  4. 4Find files without an owner after a delete

    find / -xdev -nouser 2>/dev/null

    A security check: orphan files can be taken over by a new user with the same UID.

  5. 5Check that nobody uses the account

    who | grep olduser; pgrep -u olduser

    userdel refuses when the user has processes (exit code 8).

  6. 6Stop the processes, then delete

    pkill -KILL -u olduser; userdel -r olduser

    Only when you are sure the work is saved.

  7. 7Offboarding: lock first, delete later

    usermod -L -e 1 olduser

    Wait some weeks, then userdel -r olduser.

  8. 8Remove the cron jobs of the user

    crontab -r -u olduser

    userdel does not always remove them on every system.

  9. 9Archive the home folder before the delete

    tar -czf /root/olduser-home.tgz -C /home olduser && userdel -r olduser

    Keep a copy for the legal hold period.

  10. 10Delete a service account

    userdel myapp

    Its data in /var/lib/myapp stays; remove it yourself.

  11. 11Check that it is gone

    id olduser
    id: 'olduser': no such user

    The account is removed.

Let op

  • Files outside the home folder are not removed.
  • -f can remove a group that other users still use as primary group.

Bestanden

/etc/passwd, /etc/shadow, /etc/group, /etc/gshadow
The account files.
/etc/login.defs
USERGROUPS_ENAB decides if the private group is removed.

Exitcodes

0Done.
1Could not update the password file.
2Wrong syntax.
6The user does not exist.
8The user is logged in.
10Could not update the group file.
12Could not remove the home folder.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man 8 userdel