{
    "mode": "man",
    "parameter": "userdel",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/userdel/8/json",
    "generated": "2026-06-02T21:25:53Z",
    "synopsis": "userdel [options] LOGIN",
    "sections": {
        "NAME": {
            "content": "userdel - delete a user account and related files\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "userdel [options] LOGIN\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "userdel is a low level utility for removing users. On Debian, administrators should usually\nuse deluser(8) instead.\n\nThe userdel command modifies the system account files, deleting all entries that refer to the\nuser name LOGIN. The named user must exist.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "The options which apply to the userdel command are:\n",
            "subsections": [
                {
                    "name": "-f --force",
                    "content": "This option forces the removal of the user account, even if the user is still logged in.\nIt also forces userdel to remove the user's home directory and mail spool, even if\nanother user uses the same home directory or if the mail spool is not owned by the\nspecified user. If USERGROUPSENAB is defined to yes in /etc/login.defs and if a group\nexists with the same name as the deleted user, then this group will be removed, even if\nit is still the primary group of another user.\n\nNote: This option is dangerous and may leave your system in an inconsistent state.\n",
                    "flag": "-f",
                    "long": "--force"
                },
                {
                    "name": "-h --help",
                    "content": "Display help message and exit.\n",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-r --remove",
                    "content": "Files in the user's home directory will be removed along with the home directory itself\nand the user's mail spool. Files located in other file systems will have to be searched\nfor and deleted manually.\n\nThe mail spool is defined by the MAILDIR variable in the login.defs file.\n",
                    "flag": "-r",
                    "long": "--remove"
                },
                {
                    "name": "-R --root",
                    "content": "Apply changes in the CHROOTDIR directory and use the configuration files from the\nCHROOTDIR directory.\n",
                    "flag": "-R",
                    "long": "--root"
                },
                {
                    "name": "-P --prefix",
                    "content": "Apply changes in the PREFIXDIR directory and use the configuration files from the\nPREFIXDIR directory. This option does not chroot and is intended for preparing a\ncross-compilation target. Some limitations: NIS and LDAP users/groups are not verified.\nPAM authentication is using the host files. No SELINUX support.\n",
                    "flag": "-P",
                    "long": "--prefix"
                },
                {
                    "name": "-Z --selinux-user",
                    "content": "Remove any SELinux user mapping for the user's login.\n",
                    "flag": "-Z",
                    "long": "--selinux-user"
                }
            ]
        },
        "CONFIGURATION": {
            "content": "The following configuration variables in /etc/login.defs change the behavior of this tool:\n",
            "subsections": [
                {
                    "name": "MAIL___DIR (string)",
                    "content": "The mail spool directory. This is needed to manipulate the mailbox when its corresponding\nuser account is modified or deleted. If not specified, a compile-time default is used.\n"
                },
                {
                    "name": "MAIL___FILE (string)",
                    "content": "Defines the location of the users mail spool files relatively to their home directory.\n\nThe MAILDIR and MAILFILE variables are used by useradd, usermod, and userdel to create,\nmove, or delete the user's mail spool.\n"
                },
                {
                    "name": "MAX___MEMBERS___PER___GROUP (number)",
                    "content": "Maximum members per group entry. When the maximum is reached, a new group entry (line) is\nstarted in /etc/group (with the same name, same password, and same GID).\n\nThe default value is 0, meaning that there are no limits in the number of members in a\ngroup.\n\nThis feature (split group) permits to limit the length of lines in the group file. This\nis useful to make sure that lines for NIS groups are not larger than 1024 characters.\n\nIf you need to enforce such limit, you can use 25.\n\nNote: split groups may not be supported by all tools (even in the Shadow toolsuite). You\nshould not use this variable unless you really need it.\n"
                },
                {
                    "name": "USERDEL___CMD (string)",
                    "content": "If defined, this command is run when removing a user. It should remove any at/cron/print\njobs etc. owned by the user to be removed (passed as the first argument).\n\nThe return code of the script is not taken into account.\n\nHere is an example script, which removes the user's cron, at and print jobs:\n\n#! /bin/sh\n\n# Check for the required argument.\nif [ $# != 1 ]; then\necho \"Usage: $0 username\"\nexit 1\nfi\n\n# Remove cron jobs.\ncrontab -r -u $1\n\n# Remove at jobs.\n# Note that it will remove any jobs owned by the same UID,\n# even if it was shared by a different username.\nATSPOOLDIR=/var/spool/cron/atjobs\nfind $ATSPOOLDIR -name \"[^.]*\" -type f -user $1 -delete \\;\n\n# Remove print jobs.\nlprm $1\n\n# All done.\nexit 0\n\n\n"
                },
                {
                    "name": "USERGROUPS___ENAB (boolean)",
                    "content": "If set to yes, userdel will remove the user's group if it contains no more members, and\nuseradd will create by default a group with the name of the user.\n"
                }
            ]
        },
        "FILES": {
            "content": "/etc/group\nGroup account information.\n\n/etc/login.defs\nShadow password suite configuration.\n\n/etc/passwd\nUser account information.\n\n/etc/shadow\nSecure user account information.\n\n/etc/subgid\nPer user subordinate group IDs.\n\n/etc/subuid\nPer user subordinate user IDs.\n",
            "subsections": []
        },
        "EXIT VALUES": {
            "content": "The userdel command exits with the following values:\n\n0\nsuccess\n\n1\ncan't update password file\n\n2\ninvalid command syntax\n\n6\nspecified user doesn't exist\n\n8\nuser currently logged in\n\n10\ncan't update group file\n\n12\ncan't remove home directory\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "userdel will not allow you to remove an account if there are running processes which belong\nto this account. In that case, you may have to kill those processes or lock the user's\npassword or account and remove the account later. The -f option can force the deletion of\nthis account.\n\nYou should manually check all file systems to ensure that no files remain owned by this user.\n\nYou may not remove any NIS attributes on a NIS client. This must be performed on the NIS\nserver.\n\nIf USERGROUPSENAB is defined to yes in /etc/login.defs, userdel will delete the group with\nthe same name as the user. To avoid inconsistencies in the passwd and group databases,\nuserdel will check that this group is not used as a primary group for another user, and will\njust warn without deleting the group otherwise. The -f option can force the deletion of this\ngroup.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "chfn(1), chsh(1), passwd(1), login.defs(5), gpasswd(8), groupadd(8), groupdel(8),\ngroupmod(8), subgid(5), subuid(5), useradd(8), usermod(8).\n\n\n\nshadow-utils 4.8.1                           02/06/2024                                   USERDEL(8)",
            "subsections": []
        }
    },
    "summary": "userdel - delete a user account and related files",
    "flags": [
        {
            "flag": "-f",
            "long": "--force",
            "arg": null,
            "description": "This option forces the removal of the user account, even if the user is still logged in. It also forces userdel to remove the user's home directory and mail spool, even if another user uses the same home directory or if the mail spool is not owned by the specified user. If USERGROUPSENAB is defined to yes in /etc/login.defs and if a group exists with the same name as the deleted user, then this group will be removed, even if it is still the primary group of another user. Note: This option is dangerous and may leave your system in an inconsistent state."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "Display help message and exit."
        },
        {
            "flag": "-r",
            "long": "--remove",
            "arg": null,
            "description": "Files in the user's home directory will be removed along with the home directory itself and the user's mail spool. Files located in other file systems will have to be searched for and deleted manually. The mail spool is defined by the MAILDIR variable in the login.defs file."
        },
        {
            "flag": "-R",
            "long": "--root",
            "arg": null,
            "description": "Apply changes in the CHROOTDIR directory and use the configuration files from the CHROOTDIR directory."
        },
        {
            "flag": "-P",
            "long": "--prefix",
            "arg": null,
            "description": "Apply changes in the PREFIXDIR directory and use the configuration files from the PREFIXDIR directory. This option does not chroot and is intended for preparing a cross-compilation target. Some limitations: NIS and LDAP users/groups are not verified. PAM authentication is using the host files. No SELINUX support."
        },
        {
            "flag": "-Z",
            "long": "--selinux-user",
            "arg": null,
            "description": "Remove any SELinux user mapping for the user's login."
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "chfn",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/chfn/1/json"
        },
        {
            "name": "chsh",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/chsh/1/json"
        },
        {
            "name": "passwd",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/passwd/1/json"
        },
        {
            "name": "login.defs",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/login.defs/5/json"
        },
        {
            "name": "gpasswd",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/gpasswd/8/json"
        },
        {
            "name": "groupadd",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/groupadd/8/json"
        },
        {
            "name": "groupdel",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/groupdel/8/json"
        },
        {
            "name": "groupmod",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/groupmod/8/json"
        },
        {
            "name": "subgid",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/subgid/5/json"
        },
        {
            "name": "subuid",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/subuid/5/json"
        },
        {
            "name": "useradd",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/useradd/8/json"
        },
        {
            "name": "usermod",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/usermod/8/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Remove a user account or remove a user from a group.",
        "examples": [
            {
                "description": "Remove a user",
                "command": "sudo userdel {{username}}"
            },
            {
                "description": "Remove a user in other root directory",
                "command": "sudo userdel {{-R|--root}} {{path/to/other_root}} {{username}}"
            },
            {
                "description": "Remove a user along with the home directory and mail spool",
                "command": "sudo userdel {{-r|--remove}} {{username}}"
            }
        ]
    }
}