Skip to main content

A command to list all users? And how to add, delete, modify users?

I need a command to list all users in terminal. And how to add, delete, modify users from terminal.

Solution:
 
To list all local users you can use:

cut -d: -f1 /etc/passwd
To list all users capable of authenticating (in some way), including non-local, see this reply: https://askubuntu.com/a/414561/571941

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

To add a new user you can use:

sudo adduser new_username
or:

sudo useradd new_username
See also: What is the difference between adduser and useradd?

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

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

sudo rm -r /home/username
(Please use with caution the above command!)

To modify the username of a user:

usermod -l new_username old_username
To change the password for a user:

sudo passwd username
To change the shell for a user:

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

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

Comments

Popular posts from this blog

Files creation

In LINUX files can be created by using any of the three methods given below:        1.  Cat command (cat - CONCATENATION)        2. Touch command        3. Vi editor 1. cat command: cat stands for CONCATENATE. This is the basic command when we start learning LINUX/UNIX, as the name suggest it is used to create new file, concatenate files and display the content of the files on the standard output.     Different examples of cat command which will be useful for the beginners. 1. Creating new file 2. View the contents of the file 3. View the contents of  multiple files 4. Display the output of a file using page wise 5. cat command without filename arguments 6. Display the content of a file with line numbers 7. Copy the contents of a one file to another file 8. Appending the contents of one file to another file 9. Redirecting the output of multiple files into a single fi...

Grep Command Examples of How to Search a File for a Pattern

The UNIX Grep command searches files for a user-specified text pattern. It returns a list of the matching words or shows each line of text that contains them. You can broaden the results by using wildcards. Grep also has the ability to count instances of a search phrase that appear in a file. The syntax for this UNIX command includes three parameters, but only the text pattern is required: grep [options] pattern [filename] If it contains multiple words or special characters, be sure to place single quotation marks before and after the pattern. The UNIX shell does not interpret dollar signs, brackets, parentheses, pipes or asterisks in the same way as letters. For example, an asterisk is treated as a wildcard when you don't use quotes. If you leave out the filename, UNIX will collect data from the standard input device. This is usually the keyboard. (1) Basic search with no options The following example shows what happens if you use grep to search for the word "unix...