How to check the list of users in Linux?

Keeping track of the users on your machine can make a big difference, especially if you are a server administrator. With a few handy terminal commands, Linux makes it easy to manage users on your system.

In this article, we will see how to check the user list on your Linux machine.

Also read : How do I install Kali Linux on Virtualbox?

All local user information is stored in /etc/passwd. You can use cat or less to open the file.

cat /etc/passwd

Each line of the file has seven fields, separated by colons, that contain separate information about a particular user in the following opera.

  • Username :
  • Encrypted password (if you see x, it means the password is stored in /etc/shadow).
  • UID (User Identifier) number.
  • GID number (group identification),
  • Enter the name of the user.
  • The user’s home directory.
  • The login shell (Bash by default).

You can filter this information using the awk or cut command. In the following examples, we will use these commands only to print the username of each user.

awk -F : ‘{ print $1}’ /etc/passwd

cut -d : -f1 /etc/passwd

The result will look like this.

Also read : How to delete a directory under Linux?

The getent command displays all database records configured in /etc/nsswitch/conf. This includes the data in /etc/passwd.

earned passport

As with the /etc/passwd file, we can use the awk or cut commands to extract specific information from this list.

read passport | awk -F : ‘{print $1}}

Get pass | cut -d : -f1

Note that if you use LDAP to authenticate users, getent will retrieve all Linux users from both the /etc/passwd file and the LDAP database.

Also read : Mint vs. Ubuntu: Comparison of Linux distributions

Now that we have a complete list of all users on our system, we can use a simple grep query to find out if a particular user exists on your system.

Get a passport. Grep Codery.

As you can see, the above command queries the passwd file and finds the associated username, indicating that the user exists on the system.

You can even omit the grep command.

found password

To determine the number of users on your Linux machine, use the following command.

get an ID card | wc -l

Also read : How to use the SCP command to transfer files under Linux?

Now if you’re wondering why you have so many users on your Linux machine when you only use one or two accounts, the answer is that Linux itself creates a number of accounts during installation.

Technically, there is no difference between the system and normal users. System users are located during the Linux installation, while normal users are those you can create later. Normally, a normal user has a real login shell and a home directory.

Each user in your system has a user ID, also called a UID. If you do not specify a UID when you create a user with the useradd command, the operating system automatically assigns one from /etc/login.defs. This assignment is based on your UID_MIN and UID_MAX values.

To determine the UID range on your system, use the following command.

grep -E ‘^UID_MIN|^UID_MAX’ /etc/login.defs

Now that we know our UID range, we can retrieve a list of the system’s normal users.

get a passport {1000…60000}

Again, you can run the output of the above command through awk or cut it and get only the information you need. In this case we receive the username of the account.

evalent get passwd {$(awk ‘/^UID_MIN/ {print $2}’ /etc/login.defs)}..$(awk ‘/^UID_MAX/ {print $2}’ /etc/login.defs)}. | cut -d : -f1

Also read : How do I rename a file under Linux?

The one who writes/cuts/films/owns all the technology, and when he’s not around, switches to virtual machine races. You can contact Yadullah at [email protected], or follow him on Instagram or Twitter.

frequently asked questions

How can I see a list of Linux users?

In this post, you will learn how to register users with Lux.

How do I get a list of users under Unix?

A list of all Unix users. To list all users on a Unix system, even those who are not logged in, look in the /etc/password file. Use the Cut command to see only one field in the password file. A z. B. To see only the names of Unix users, use the command $ cat /etc/passwd | cut -d : -f1.

linux command to list all users,linux list all users,list users in linux,linux list users logged in,how to check current user in linux,linux list users and groups,Feedback,Privacy settings,How Search works,default users in linux,list groups linux

You May Also Like