الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

userdel

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

المستوى
امتحان RHCSA
المجموعة
المستخدمون والمجموعات
يحتاج root
نعم
الحزمة
shadow-utils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

userdel [OPTION]... LOGIN

الخيارات 6

الأكثر استخدامًا

-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.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع 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.

انتبه

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

الملفات

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

رموز الخروج

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.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man 8 userdel