deluser (从系统中删除用户或组)

瑞兹 发表于 2021-01-08 09:08
浏览次数:
在手机上阅读

在Linux操作系统上,deluser和delgroup命令从系统中删除用户或组。

查看英文版

目录

1 deluser 运行系统环境

2 deluser 描述

3 deluser 语法

4 deluser 例子

deluser 运行系统环境

Unix&Linux

deluser 描述

deluserdelgroup根据命令行选项和/etc/deluser.conf/etc/adduser.conf中的配置信息从系统中删除用户和组。它们是userdel和groupdel程序的更友好的前端,可以删除主目录作为选项,甚至可以删除要删除的用户拥有的系统上的所有文件,并运行自定义脚本和其他功能。deluserdelgroup可以以下三种模式之一运行:

删除普通用户

如果一个非选项称为参数和不--group选项,deluser将删除普通用户。

默认情况下,deluser将删除用户而不删除主目录,邮件后台打印或该用户拥有的系统上的任何其他文件。可以使用--remove-home选项删除主目录和邮件假脱机。

--remove-所有文件选项删除用户所拥有的系统上的所有文件。请注意,如果同时激活这两个选项,则--remove-home将不起作用,因为--remove-all-files选项已覆盖所有文件,包括主目录和邮件后台打印程序

如果要在删除所有文件之前备份所有文件,则可以激活--backup选项,该选项将在--backup-to选项指定的目录中创建文件username.tar.gz | .bz2)(默认为当前文件)。工作目录)。默认情况下,还可以在配置文件/etc/deluser.conf中激活删除和备份选项。有关详细信息,请参见deluser.conf

如果要删除根帐户(uid 0),请使用--force 参数;这样可以防止意外删除root用户。

如果文件/usr/local/sbin/deluser.local存在,将在删除用户帐户以执行任何本地清理后执行该文件。传递给deluser.local的参数为:“ username uid gid home-directory ”。

删除组

如果deluser时调用--group选项,或delgroup被调用,一组将被删除。

警告:无法删除现有用户的主要组。

如果指定了--only-if-empty选项,则如果该组中有剩余成员,则不会删除该组。

从特定组中删除用户

如果使用两个非选项参数调用,则deluser将从特定组中删除用户。

deluser and delgroup remove users and groups from the system according to command line options and configuration information in /etc/deluser.conf and /etc/adduser.conf. They are friendlier front ends to the userdel and groupdel programs, removing the home directory as option or even all files on the system owned by the user to be removed, running a custom script, and other features. deluser and delgroup can be run in one of three modes:

To Remove A Normal User

If called with one non-option argument and without the --group option, deluser will remove a normal user.

By default, deluser will remove the user without removing the home directory, the mail spool or any other files on the system owned by the user. Removing the home directory and mail spool can be achieved using the --remove-home option.

The --remove-all-files option removes all files on the system owned by the user. Note that if you activate both options --remove-home will have no effect because all files including the home directory and mail spool are already covered by the --remove-all-files option.

If you want to backup all files before deleting them you can activate the --backup option which will create a file username.tar(.gz|.bz2) in the directory specified by the --backup-to option (defaulting to the current working directory). Both the remove and backup options can also be activated for default in the configuration file /etc/deluser.conf. See deluser.conf for details.

If you want to remove the root account (uid 0), then use the --force parameter; this prevents removing the root user by accident.

If the file /usr/local/sbin/deluser.local exists, it will be executed after the user account has been removed to do any local cleanup. The arguments passed to deluser.local are: "username uid gid home-directory".

To Remove A Group

If deluser is called with the --group option, or delgroup is called, a group will be removed.

Warning: The primary group of an existing user cannot be removed.

If the option --only-if-empty is given, the group won't be removed if it has any members left.

To Remove A User From A Specific Group

If called with two non-option arguments, deluser will remove a user from a specific group.

查看英文版

查看中文版

deluser 语法

deluser [--quiet] [--system] [--help] [--version] [--conf FILE] [--force]
        [--remove-home] [--remove-all-files] [--backup]
        [--backup-to DIR] user 
deluser --group [--quiet] [--system] [--help] [--version]
        [--conf FILE] group 
delgroup [options] [--quiet] [--system] [--help] [--version]
         [--conf FILE] group 
deluser [options] user group 

Options

--conf FILE

使用FILE而不是默认文件/etc/deluser.conf/etc/adduser.conf

--group

删除组。如果以delgroup调用程序,则这是默认操作。

--help

显示帮助消息,然后退出。

--quiet

禁止显示进度消息。

--system

仅当用户/组是系统用户/组时才删除。这样可以避免意外删除非系统用户/组。此外,如果用户不存在,则不会返回错误值。

--backup

将userhome和mailspool文件中包含的所有文件备份到名为/$user.tar.bz2/$user.tar.gz的文件中。

--backup-to

将备份文件放置在此参数指定的目录中,而不要放在/中。这也隐式设置--backup

--remove-home

删除用户的主目录及其邮件池。如果指定了--backup,则在执行备份后删除文件。

--remove-all-files

从该用户拥有的系统中删除所有文件。注意:-- remove-home不再起作用。如果指定了--backup,则在执行备份后删除文件。

--version

显示版本和版权信息。

组态

文件/etc/deluser.conf包含程序deluserdelgroup的默认值。每个选项均采用“ option value ”的形式。值周围可以使用双引号或单引号。注释行的开头必须有一个井号(“  ”)。

deluserdelgroup也读取/etc/adduser.conf,请参见adduser.conf;在设置deluser.conf可以覆盖在所做的设置adduser.conf

有效的配置选项是:

REMOVE_HOME

删除要删除的用户的主目录和邮件后台打印程序。值可以是0(不删除)或1(要删除)。

REMOVE_ALL_FILES

删除要删除的用户拥有的系统上的所有文件。如果激活此选项,则REMOVE_HOME不起作用。值可以是01

BACKUP

如果激活REMOVE_HOMEREMOVE_ALL_FILES,则在删除所有文件之前先对其进行备份。在BACKUP_TO选项指定的目录中,创建的备份文件默认为username.tar.gz | .bz2)。尽量选择压缩方法。值可以是01

BACKUP_TO

如果激活了BACKUP,则BACKUP_TO指定要写入备份的目录。默认为当前目录。

NO_DEL_PATHS

正则表达式列表,以空格分隔。对照这些正则表达式中的每一个,检查在删除主目录或删除要删除的用户拥有的文件过程中要删除的所有文件。如果检测到匹配项,则不会删除该文件。默认为系统目录列表,仅保留/ home

换句话说:默认情况下,仅/ home下面属于该特定用户的文件将被删除。

ONLY_IF_EMPTY

仅当没有用户属于该组时才删除该组。默认为0

EXCLUDE_FSTYPES

一个正则表达式,描述寻找要删除的用户文件时应排除的所有文件系统。默认为“ (proc | sysfs | usbfs | devpts | tmpfs | afs) ”。

返回值

0

该操作已成功执行。

1

要删除的用户不是系统帐户。没有执行任何操作。

2

没有这样的用户。没有执行任何操作。

3

没有这样的团体。没有执行任何操作。

4

内部错误。没有执行任何操作。

5

要删除的组不为空。没有执行任何操作。

6

该用户不属于指定的组。没有执行任何操作。

7

您不能从其主要组中删除用户。没有执行任何操作。

8

未安装所需的perl软件包“ perl模块”。需要此软件包才能执行请求的操作。没有执行任何操作。

9

要删除root帐户,需要参数“ --force ”。没有执行任何操作。

档案

/etc/deluser.conf

Configuration file.

deluser [--quiet] [--system] [--help] [--version] [--conf FILE] [--force]
        [--remove-home] [--remove-all-files] [--backup]
        [--backup-to DIR] user 
deluser --group [--quiet] [--system] [--help] [--version]
        [--conf FILE] group 
delgroup [options] [--quiet] [--system] [--help] [--version]
         [--conf FILE] group 
deluser [options] user group 

Options

--conf FILE

Use FILE instead of the default files /etc/deluser.conf and /etc/adduser.conf

--group

Remove a group. This is the default action if the program is invoked as delgroup.

--help

Display a help message, and exit.

--quiet

Suppress progress messages.

--system

Only delete if user/group is a system user/group. This avoids accidentally deleting non-system users/groups. Additionally, if the user does not exist, no error value is returned.

--backup

Backup all files contained in the userhome and the mailspool file to a file named /$user.tar.bz2 or /$user.tar.gz.

--backup-to

Place the backup files not in / but in the directory specified by this parameter. This implicitly sets --backup also.

--remove-home

Remove the home directory of the user and its mailspool. If --backup is specified, the files are deleted after having performed the backup.

--remove-all-files

Remove all files from the system owned by this user. Note: --remove-home does not have an effect any more. If --backup is specified, the files are deleted after having performed the backup.

--version

Display version and Copyright information.

Configuration

The file /etc/deluser.conf contains defaults for the programs deluser and delgroup. Each option takes the form "option = value". Double or single quotes are allowed around the value. Comment lines must have a hash sign ("#") at the beginning of the line.

deluser and delgroup also read /etc/adduser.conf, see adduser.conf; settings in deluser.conf may overwrite settings made in adduser.conf.

The valid configuration options are:

REMOVE_HOME

Removes the home directory and mail spool of the user to be removed. Value may be 0 (don't delete) or 1 (do delete).

REMOVE_ALL_FILES

Removes all files on the system owned by the user to be removed. If this option is activated REMOVE_HOME has no effect. Values may be 0 or 1.

BACKUP

If REMOVE_HOME or REMOVE_ALL_FILES is activated, all files are backed up before they are removed. The backup file that is created defaults to username.tar(.gz|.bz2) in the directory specified by the BACKUP_TO option. The compression method is chosen to the best that is available. Values may be 0 or 1.

BACKUP_TO

If BACKUP is activated, BACKUP_TO specifies the directory to write the backup. Default is the current directory.

NO_DEL_PATHS

A list of regular expressions, space-separated. All files to be deleted in course of deleting home directories or deleting files owned by the user to be deleted are checked against each of these regular expressions. If a match is detected, the file is not deleted. Defaults to a list of system directories, leaving only /home.

In other words: By default, only files below /home belonging to that specific user are going to be deleted.

ONLY_IF_EMPTY

Only delete a group if there are no user who belong to this group. Defaults to 0.

EXCLUDE_FSTYPES

A regular expression which describes all file systems which should be excluded when looking for files of a user to be deleted. Defaults to "(proc|sysfs|usbfs|devpts|tmpfs|afs)".

Return Value

0

The action was successfully executed.

1

The user to delete was not a system account. No action was performed.

2

There is no such user. No action was performed.

3

There is no such group. No action was performed.

4

Internal error. No action was performed.

5

The group to delete is not empty. No action was performed.

6

The user does not belong to the specified group. No action was performed.

7

You cannot remove a user from its primary group. No action was performed.

8

The required perl package 'perl modules' is not installed. This package is required to perform the requested actions. No action was performed.

9

For removing the root account the parameter "--force" is required. No action was performed.

Files

/etc/deluser.conf

Configuration file.

查看英文版

查看中文版

deluser 例子

deluser myuser

删除用户帐户myuser

deluser --remove-home myuser

删除用户帐户myuser,同时也删除该用户的主目录。

deluser --force myuser

删除用户帐户myuser,即使该用户当前已登录。

deluser --backup-to /directory myuser

删除用户帐户myuser并将其文件备份到名为myuser.tartar归档文件中,该归档文件在目录/ directory中创建。

delgroup mygroup

删除组mygroup

deluser myuser

Deletes the user account myuser.

deluser --remove-home myuser

Deletes the user account myuser, and removes that user's home directory as well.

deluser --force myuser

Deletes the user account myuser even if that user is currently logged in.

deluser --backup-to /directory myuser

Deletes the user account myuser and backs up their files in a tar archive called myuser.tar, which is created in the directory /directory.

delgroup mygroup

Deletes the group mygroup.

查看英文版

查看中文版

其他命令行

date | du | dpost | dmesg | dirname | dircmp | dd | depmod | deroff | df | dhclient | diff | dos2unix | dig |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条