Raspberry Pi_Eng_12.5 “deluser” Command – Delete User


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


12.5   "deluser" Command - Delete User

 

You need to delete user account that is not needed on your system.

 

When deleting a user account, you can use "deluser" and "userdel" commands. The "deluser" command makes it easy to create user account. On the other hand, the "userdel" command can handle relatively detailed processing with very low-level commands, but it is complex to use and is not well used for general purposes.

 

The "deluser" command is used to delete a user account. Optionally, you can delete user groups at the same time while deleting user accounts. .

 

[Command Format]

deluser [options] [--force] [--remove-home] [--remove-all-files] [--backup] [--backup-to DIR] user

deluser --group [options] group

deluser [options] user group

 

[Command Overview]  

   This deletes existing user account.

   User privilege          -- Super user.

 

[Detail Description]

   The "deluser" command deletes the user from the system according to the options and settings specified in "/etc/deluser.conf" file. Depending on the option, you can delete the home directory, delete all files owned by the user being deleted, and run the necessary scripts.

   After user account has been deleted, you have to check manually that all file systems used by deleted user account are deleted.

 

[Main Option]

-h, --help

 

Display brief instructions.

--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. This option is mainly for use in Debian package maintainer scripts.

--group

 

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

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

 

[Files]

/etc/group

Group account information.

/etc/gshadow

Secure group account information.

 

[Used Example]

We want to delete the existing user "guser002". If we look in the "/etc/passwd" file before doing the delete operation, you can see that "guser002" exists.

 

pi@raspberrypi ~ $ sudo cat /etc/passwd

root:x:0:0:root:/root:/bin/bash

daemon:x:1:1:daemon:/usr/sbin:/bin/sh

~~~~~

guser001:x:1001:1004:General User 001,,,:/home/guser001:/bin/bash

guser002:x:1002:1005:General User 002,,,:/home/guser002:/bin/bash

 

To delete the existing user "guser002", do the following task.

 

pi@raspberrypi ~ $ sudo deluser guser002

 

 

If you check the data in the "/etc/passwd" file after the delete operation is completed, you can confirm that the user has been deleted.

 

pi@raspberrypi ~ $ sudo cat /etc/passwd

root:x:0:0:root:/root:/bin/bash

daemon:x:1:1:daemon:/usr/sbin:/bin/sh

~~~~~

guser001:x:1001:1004:General User 001,,,:/home/guser001:/bin/bash