Deleting users on linux

Is there a command to list all users? Also to add, delete, modify users, in the terminal?

I need a command to list all users as well as commands to add, delete and modify users from terminal — any commands that could help in administrating user accounts easily by terminal.

10 Answers 10

To list

To list all local users you can use:

To list all users capable of authenticating (in some way), including non-local, see this reply.

Some more useful user-management commands (also limited to local users):

To add

To add a new user you can use:

sudo adduser new_username
sudo useradd new_username

To remove/delete

To remove/delete a user, first you can use:

Then you may want to delete the home directory for the deleted user account :

Please use with caution the above command!

To modify

To modify the username of a user:

usermod -l new_username old_username

To change the password for a user:

To change the shell for a user:

To change the details for a user (for example real name):

To add a user to the sudo group:

And, of course, see also: man adduser , man useradd , man userdel . and so on.

Radu forgot to mention sudo chfn which changes user details (for example real name). I tried to add this as a comment, but I got error telling me that I must have +50 reputation to do so.

I think that it should be underlined that the correct answer to the linked question is askubuntu.com/a/381646/16395 — otherwise you have to take into account the GID/UID Ubuntu policies by hand. The accepted answer is not so clear.

sudo userdel DOMAIN\\johndoe gives me the error: «userdel: cannot remove entry ‘DOMAIN\johndoe’ from /etc/passwd — I looked in /etc/passwd and they’re not even in there, likely because it’s a «domain» account?

@00fruX Yeah. If you’re using a centralised user database you’re going to need to deal with it directly.

Just press Ctrl + Alt + T on your keyboard to open Terminal. When it opens, run the command(s) below:

less /etc/passwd more /etc/passwd 

@nux A bit late to the party, but from command line use adduser instead, useradd should be limited to scripts where the author really really knows what he is doing.

Manpage icon

The easiest way to get this kind of information is getent — see manpage for the getent command . While that command gives the same output as cat /etc/passwd it is useful to remember because it will give you lists of several elements in the OS.

To get a list of all users you type (as users are listed in /etc/passwd )

To add a user newuser to the system you would type

to create a user that has all default settings applied.

Bonus: To add any user (for instance anyuser) to a group (for instance cdrom) type

sudo adduser anyuser cdrom 

You delete a user (for instance obsolete) with

If you want to delete his home directory/mails as well you type

sudo deluser --remove-home obsolete 
sudo deluser --remove-all-files obsolete 

will remove the user and all files owned by this user on the whole system.

Читайте также:  What does linux x86 mean

It’s useful to remember that getent doesn’t just print the output of users in /etc/passwd but all users in all configured userdb backends on a given system, whether it’s /etc/passwd or LDAP, etc.

@MarcinKaminski is right, it also prints users setup in SSO systems who have access to the server. this answer is the the best one, with getent passwd being the right command

This should get, under most normal situations, all normal (non-system, not weird, etc) users:

awk -F'[/:]' '= 1000 && $3 != 65534) print $1>' /etc/passwd 
  • reading in from /etc/passwd
  • using : as a delimiter
  • if the third field (the User ID number) is larger than 1000 and not 65534, the first field (the username of the user) is printed.

This is because on many linux systems, usernames above 1000 are reserved for unprivileged (you could say normal) users. Some info on this here:

A user ID (UID) is a unique positive integer assigned by a Unix-like operating system to each user. Each user is identified to the system by its UID, and user names are generally used only as an interface for humans.

UIDs are stored, along with their corresponding user names and other user-specific information, in the /etc/passwd file.

The third field contains the UID, and the fourth field contains the group ID (GID), which by default is equal to the UID for all ordinary users.

In the Linux kernels 2.4 and above, UIDs are unsigned 32-bit integers that can represent values from zero to 4,294,967,296. However, it is advisable to use values only up to 65,534 in order to maintain compatibility with systems using older kernels or filesystems that can only accommodate 16-bit UIDs.

The UID of 0 has a special role: it is always the root account (i.e., the omnipotent administrative user). Although the user name can be changed on this account and additional accounts can be created with the same UID, neither action is wise from a security point of view.

The UID 65534 is commonly reserved for nobody, a user with no system privileges, as opposed to an ordinary (i.e., non-privileged) user. This UID is often used for individuals accessing the system remotely via FTP (file transfer protocol) or HTTP (hypertext transfer protocol).

UIDs 1 through 99 are traditionally reserved for special system users (sometimes called pseudo-users), such as wheel, daemon, lp, operator, news, mail, etc. These users are administrators who do not need total root powers, but who perform some administrative tasks and thus need more privileges than those given to ordinary users.

Some Linux distributions (i.e., versions) begin UIDs for non-privileged users at 100. Others, such as Red Hat, begin them at 500, and still others, such Debian, start them at 1000. Because of the differences among distributions, manual intervention can be necessary if multiple distributions are used in a network in an organization.

Also, it can be convenient to reserve a block of UIDs for local users, such as 1000 through 9999, and another block for remote users (i.e., users elsewhere on the network), such as 10000 to 65534. The important thing is to decide on a scheme and adhere to it.

Among the advantages of this practice of reserving blocks of numbers for particular types of users is that it makes it more convenient to search through system logs for suspicious user activity.

Contrary to popular belief, it is not necessary that each entry in the UID field be unique. However, non-unique UIDs can cause security problems, and thus UIDs should be kept unique across the entire organization. Likewise, recycling of UIDs from former users should be avoided for as long as possible.

Источник

Читайте также:  Удалить двойную загрузку linux

How to Delete/Remove Users in Linux (userdel Command)

Linux is a multi-user system, which means that more than one person can interact with the same system at the same time. As a system administrator, you have the responsibility to manage the system’s users and groups by creating new users and assign them to different groups .

Occasionally, you might need to delete a user account. Perhaps because the user moved away from the organization, or it was created for a specific service that no longer runs on the system.

In Linux, you can delete a user account and all its associated files using the userdel command.

This tutorial covers the userdel command and its options.

userdel Command Syntax #

The syntax for the userdel command is as follows:

To delete users using the userdel command, you need to be logged in as root or a user with sudo access.

How to Delete User in Linux #

To delete a user account named username using the userdel command you would run:

When invoked, the command reads the content of the /etc/login.defs file. Properties defined in this file override the default behavior of userdel . If USERGROUPS_ENAB is set to yes in this file, userdel deletes the group with the same name as the user, only if no other user is a member of this group.

The command removes the user entries from the /etc/passwd and /etc/shadow, files.

In most Linux distributions, when removing a user account with userdel , the user home and mail spool directories are not removed.

Use the -r ( —remove ) option to force userdel to remove the user’s home directory and mail spool:

The command above does not remove the user files located in other file systems. You have to search for and delete the files manually.

If the user you want to remove is still logged in, or if there are running processes that belong to this user, the userdel command does not allow to remove the user.

In this situation, it is recommended to log out the user and kill all user’s running processes with the killall command:

Once done, you can remove the user.

Another option is to use the -f ( —force ) option that tells userdel to forcefully remove the user account, even if the user is still logged in or if there are running processes that belong to the user.

Conclusion #

In this tutorial, you learned how to delete user accounts in Linux using the userdel command. The same syntax applies for any Linux distribution, including Ubuntu, CentOS, RHEL, Debian, Fedora, and Arch Linux.

userdel is a low-level utility, Debian and Ubuntu users will more likely use the friendlier deluser command instead.

Feel free to leave a comment if you have any questions.

Источник

How to Delete User on Ubuntu

Ubuntu is a well liked and widely used Linux distribution which allows you to add and delete use. Ubuntu is an operating system that handles several people who can use the system at the same time. When you install the Ubuntu system you need to create the user and you can add users later after installation of the system. But if you want to remove any users then Ubuntu allows you to delete the user using sudo privileges. In this Article our main focus will be on how to remove a user from Ubuntu using two approaches: Deleting user using Graphical Interface and Deleting user using Command Line.

Читайте также:  Посмотреть часовой пояс linux

Follow any of the approaches you find easier.

Deleting User Using Graphical Interface

As a beginner of Ubuntu you will find this approach a way easier. Follow the steps below to remove user using GUI on Ubuntu System:

Step 1: Open setting
Firstly you need to open the Settings by opening “Activities” and typing setting in search bar and click on Settings icon:

Or you can left click on the desktop screen of Ubuntu a drop-down list will appear, click on Settings option.

Step 2: Open Users setting
After the setting window will appear click on “Users” from list on left side, then on “Unlock…”:

Step 3: Remove User Account
In the Users setting, the system users will be shown on the screen.Then, at the bottom of the page, click the “Remove User…” button next to the user you wish to delete. Below I am removing “linuxhint” user from my system:

Now a dialogue box will appear asking you to select an option. To remove all files of the user you want to delete then choose Delete Files option, but if you want to store the files of the user for later use then choose Keep Files option.

And user will be removed from list of users as shown below:

Deleting User using Command Line

If you are a Command Line user this method is for you. You can also remove the user by writing commands on the terminal.

Step 1: List users
First check all the users registered on your system, the users are recorded in /etc/passwd, with the user account name as the first column.To see a list of existing user accounts, use the cat command, as seen below:

Step 2: Remove user
The “deluser” command is used for deleting or removing a user account from Ubuntu. The deluser command should be given the user account name. We also need capabilities to delete user accounts, which we can get by logging in as root or executing the sudo command as a regular user.

Below mentioned is the command to delete “linuxhint” user from my system:

Step 3 : Check User
Now check whether the user is deleted by below mentioned command:

From above shown results we can check that “linuxhint” user no longer exists.

Conclusion

Ubuntu is an open source multi-user Linux distribution which provides several functionalities.It lets you add and remove users at any moment. In this Article, two approaches to delete the user from Ubuntu system are discussed; first is by GUI method and second is by Command line method using “deluser” command. To successfully delete the user, you can use any of the methods outlined in this article.

About the author

Alishba Iftikhar

I am currently an undergraduate student in my 1st year. I am an internee author with Linuxhint and loved learning the art of technical content writing from senior authors. I am looking forward to opting my career as a full time Linux writer after I graduate.

Источник

Оцените статью
Adblock
detector