Linux show user info

11 Ways to Find User Account Info and Login Details in Linux

This article will show you eleven useful ways to find the information about users on a Linux system. Here we’ll describe commands to get a user’s account details, show login details as well as what users are doing on the system.

If you want to add users in Linux, use the useradd utility, and to modify or change any attributes of a already created user account, use the usermod via the command line as explained in the following guides:

We’ll start by looking at commands to find a user’s account information, then proceed to explain commands to view login details.

1. id Command

id is a simple command line utility for displaying a real and effective user and group IDs as follows.

2. groups Command

groups command is used to show all the groups a user belongs to like this.

3. finger Command

finger command is used to search information about a user on Linux. It doesn’t come per-installed on many Linux systems.

To install it on your system, run this command on the terminal.

It shows a user’s real name; home directory; shell; login: name, time; and so much more as below.

4. getent Command

getent is a command line utility for fetching entries from Name Service Switch (NSS) libraries from a specific system database.

To get a user’s account details, use the passwd database and the username as follows.

5. grep Command

grep command is a powerful pattern searching tool available on most if not all Linus systems. You can use it to find information about a specific user from the system accounts file: /etc/passwd as shown below.

6. lslogins Command

lslogins command shows information about known users in the system, the -u flag only displays user accounts.

7. users Command

users command shows the usernames of all users currently logged on the system like so.

8. who Command

who command is used to display users who are logged on the system, including the terminals they are connecting from.

9. w Command

w command shows all users who are logged on the system and what they are doing.

10. last or lastb commands

last/lastb commands displays a list of last logged in users on the system.

To show all the users who were present at a specified time, use the -p option as follows.

11. lastlog Command

lastlog command is used to find the details of a recent login of all users or of a given user as follows.

That’s it! If you know any other command-line trick or command to view user account details do share with us.

You’ll find these related article so useful:

In this article, we’ve explained various ways to find information about users and login details on a Linux system. You can ask any questions or share your thoughts via the feedback form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Linux List All Users In The System Command

Table of contents

Linux list all users account using the /etc/passwd file

In order to list all users on Linux, use the cat command as follows:
$ cat /etc/passwd
Here is what I see:

Each line in the file has seven fields as follows. For example, consider the following line:
vnstat:x:131:137:vnstat daemon. /var/lib/vnstat:/usr/sbin/nologin
Where,

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

  • vnstat – The user name or login name.
  • x – Encrypted password is stored in the /etc/shadow file.
  • 131 – UID (user ID number)
  • 137 – Primary GID (group ID number)
  • vnstat daemon – GECOS. It may includes user’s full name (or application name, if the account is for a program), building and room number or contact person, office telephone number, home telephone number and any other contact information.
  • /var/lib/vnstat – Home directory for the user.
  • /usr/sbin/nologin – Login shell for the user. Pathnames of valid login shells comes from the /etc/shells file.

How to list users in Linux using pagers

Of course we can use pagers such as more/less commands as follows to view the /etc/passwd file:
$ more /etc/passwd
$ less /etc/passwd
Sample outputs:

Fig.01: List users using /etc/passwd

Linux list user names only

To list only usernames type the following awk command:
$ awk -F’:’ ‘< print $1>‘ /etc/passwd
Sample outputs:

Another option is to use the cut command:
$ cut -d: -f1 /etc/passwd

Get a list of all users using the getent command

To get a list of all Linux users you can type the following getent command:
$ getent passwd
$ getent passwd | grep tom
## get a list all users ##
$ getent passwd | cut -d: -f1
## count all user accounts using the wc ##
$ getent passwd | wc -l
One can use the compgen command on Linux to list users and other resources too:
$ compgen -u

Find out whether a user account exists in the Linux server

We can use above commands to see whether a user exists in the Linux machine as follows using the grep command:

A simplified command would be:

How to count user accounts in the Linux server

Want to get user accounts count on your system? Try the wc command as follows:
$ compgen -u | wc -l
$ getent passwd | wc -l

A Note About System and General Users

Each user has numerical user ID called UID. It is defined in /etc/passwd file. The UID for each user is automatically selected using /etc/login.defs file when you use useradd command. To see current value, enter:
$ grep «^UID_MIN» /etc/login.defs
$ grep UID_MIN /etc/login.defs
Sample outputs:

1000 is minimum values for automatic uid selection in useradd command. In other words all normal system users must have UID >= 1000 and only those users are allowed to login into system if shell is bash/csh/tcsh/ksh etc as defined /etc/shells file. Type the following command to list all login users:

To see maximum values for automatic uid selection in the useradd command, enter:
$ grep «^UID_MAX» /etc/login.defs
Sample outputs:

In other words, all normal system users must have UID >= 1000 (MIN) and UID /etc/shells file. Here is an updated code to get details:

Источник

3 Ways to List Users in Linux

Today different Operating Systems have the capability to use multiple users, each one with their settings and custom configurations to make things easier for administrators and operators to work in together on the same system.

Linux on the other hand is very strong on this matter as it allows multiple users to work at the same time on the system in an independent way. It can even allow a single user to open several sessions even from different locations in order to work on the system.

Here are some hints & tricks to handle users in Linux.

List all the users on Linux

Let’s say you want to create a sudo user in Linux. Probably, the very first thing to know is how to know what users are in my system. There are several ways you can obtain the list of users in Linux.

1. Show users in Linux using less /etc/passwd

This command allows sysops to list the the users that are locally stored in the system. It will give the listing in structured way as:

The structure in the above output goes as:

  • User name
  • Encrypted password ( x represents password is stored)
  • User ID number (UID)
  • User’s group ID number (GID)
  • Full name
  • User’s home directory
  • User’s Login shell (default is bash shell)

Why so many users? Which ones are ‘real’?

The list shows a lot more users than you expected because it lists all the system users too.

Now if you want to distinguish the normal users from the system users, you can refer to the User identifier (UID) number.

Generally, a normal user has UID greater or equal to 1000. This gives you a hint that the user with UID >=1000 is a normal user and users with UID

Источник

How To View System Users in Linux on Ubuntu

Published on September 5, 2013

Introduction

A fundamental part of system administration is configuring and managing users and groups. Part of this task involves monitoring the log in capabilities of all system entities.

In this guide, we will introduce the basic ideas behind user management and authentication logging.

We will be exploring these concepts on an Ubuntu 12.04 VPS, but you can follow along on any up-to-date Linux distribution.

Part one will cover how to view system users and find out who is logged into the system.

How To View Available Users on a VPS

Every user on a Linux system, whether created as an account for a real human being or associated with a particular service or system function, is stored in a file called «/etc/passwd«.

The «/etc/passwd» file contains information about the users on the system. Each line describes a distinct user.

Have a look by entering:

Each line is broken up into fields. These fields are delimited by the colon (:) character.

The only field that we are really interested in at the moment is the first one. Each is an independent username.

We can get this list without wading through the entire «/etc/passwd» by typing:

You probably recognize «root» as the administrative user. Towards the end, you may see the user you are logged in as.

In between, you will probably see a number of other users whose usage seems at least somewhat clear. For instance, «www-data» is configured as the owner of web server processes.

This is done to separate functional privileges. That way, if an account is compromised or misused, the affect will be isolated.

How To View Available Groups on a VPS

The corresponding file for discovering system groups is «/etc/group«.

We can see the whole file by typing:

You can see that many of the group names mirror the users we discovered on our system. This is part of a configuration scheme called «user private groups«, or UPG.

User private groups create a private group for each user and set that group as the primary group. The umask is then changed from 022 to 002.

This allows for more flexibility in shared directories by setting a flag called setgid, which gives files inside the directory the same group owner as the directory itself. This configuration is useful, but outside of the scope of this article.

Once again, we can pare down the information from the «/etc/group» file by using the cut command:

The output will be a list of each group on the system, one per line.

How To Find Which Users Are Logged In

Many times, it will be more useful to find out which users are active on your system.

The «w» command is a simple way to list all of the currently logged in users, their log in time, and what the command they are currently using:

The first line contains system uptime information. The following lines describe who is logged in.

An alternative that provides similar information is «who«:

Conclusion

User authentication on Linux is a relatively flexible area of system management. There are many ways of accomplishing the same objective with very simple tools.

You should now know how to find out where your server stores its user and group information. You can also see who is logged in at any given time.

In the next part, we will discuss how to restrict access to logins.

Authentication, Part 1 — How To View System Users in Linux on Ubuntu

Источник

6 Ways to check user information in Linux

Most of us use the id command , and some users filter the user information from the /etc/passwd file.

If you are a beginner for Linux operating systems and want to know more about the /etc/passwd file, please refer the following article.

In general, we use the above two commands to obtain user information. You may ask why to discuss this basic topic. People think there are no alternatives other other than these two commands, but we found that there are other ways to gather user information. Hence, we have created this article to guide you.

In this tutorial, we will discuss all these methods in detail. This is one of the basic commands that help the administrator to find information about a user in Linux.

Remember that everything is stored in a file on Linux, so be careful when handling the configuration file.

We have added several tweaks in this tutorial to collect user information with different aspect.

The following articles may help you to learn more about user management in Linux.

What kind of information is stored in the ‘/etc/passwd’ file

When creating users on Linux the user details are stored in the “/etc/passwd” file.

Each user information in this file is a single line with seven fields and the actual password is stored in the /etc/shadow file.

User information can be queried using these six methods:

  • id : Print user and group information for the specified username.
  • getent : Get entries from Name Service Switch libraries.
  • /etc/passwd file : The /etc/passwd file contain each/every user details as a single line with seven fields.
  • finger : User information lookup program
  • lslogins : lslogins display information about known users in the system
  • compgen : compgen is bash built-in command and it will show all available commands for the user.

1) How to check user information using id command?

The id command stands for identity. It prints real and effective user and group IDs. You can use the id command to print user and group information for the specified user, or for the current user.

Run id command without any username to print the current user information on your terminal.

To collect information on a specific user, use the id command followed by the specific username as shown below:

Details of the above output.

  • uid=500(daygeek): It shows the user ID & name
  • gid=500(daygeek): It displays the user’s primary group ID & name
  • groups=500(daygeek),10(wheel): It displays the user’s secondary groups ID & name

If you want to print multiple user information simultaneously using the id command, use the following small shell script. This script stores the list of users who have a home directory on the system in the variable.

To achieve this, write the following simple bash scripts.

Set an executable permission to “user-info.sh” file.

Finally run the script to get results:

2) Checking user information using getent command

The getent command displays entries from databases supported by the Name Service Switch libraries, which are configured in /etc/nsswitch.conf. The getent command displays user information such as the /etc/passwd file, which displays each user information on a separate line with seven fields.

The seven fields are described below in detail:

  • Username (magesh): Username of created user. Characters length should be between 1 to 32.
  • Password (x): It indicates that encrypted password is stored at /etc/shadow file.
  • User ID (UID-502): It indicates the user ID (UID) each user should be contain unique UID. UID (0-Zero) is reserved for root, UID (1-99) reserved for system users and UID (100-999) reserved for system accounts/groups
  • Group ID (GID-503): It indicates the group ID (GID) each group should be contain unique GID is stored at /etc/group file.
  • User ID Info (2g Admin — Magesh M): It indicates the command field. This field can be used to describe the user information.
  • Home Directory (/home/magesh): It indicates the user home directory.
  • shell (/bin/bash): It indicates the user’s bash shell.

If you want to display only the usernames in the getent command output, use the below format:

If you just want to display users that have home directory on system, use the below format:

Use the following format to add a UID to the getent command output:

The /etc/passwd is a text file containing every user information that is required to log in to the Linux system.

It holds useful information about users such as username, password, user ID, group ID, user ID information, home directory and shell. Each user profile in the “/etc/passwd” file is a single seperate lines with seven fields as described earlier in section #2.

If you only want to display usernames from the /etc/passwd file, use the below format:

If you only want to display users that have home directory on system, use the below format:

Use the following format to add a UID to the following command output:

If you only want to display users that have UID greater than 500 on the system, use the below format:

4) How to check user information using finger Command

The finger command displays information about the system users. It displays the user’s real name, tty name, idle time, login time, home directory and shell name.

Details of the above output.

  • Login: User’s login name
  • Name: Additional/Other information about the user
  • Directory: User home directory information
  • Shell: User’s shell information
  • LAST-LOGIN: Date of last login and other information

5) Checking user information in Linux, using lslogins command

It displays information about known users in the system. By default it will list information about all the users in the system.

The lslogins utility is inspired by the logins utility, which first appeared in FreeBSD 4.10.

Details of the above output.

  • UID: User id
  • USER: Name of the user
  • PWD-LOCK: password defined, but locked
  • PWD-DENY: login by password disabled
  • LAST-LOGIN: Date of last login
  • GECOS: Other information about the user

6) How to check user & other information in Linux, using compgen command?

The compgen is a bash built-in command and it will show all available commands, aliases, and functions for you as shown below:

Wrapping Up

In this guide, you learned several ways to find user information in Linux.

Please share this to your friends if it is helpful to you.

Источник

Читайте также:  Оптимизация дисков windows 10 расписание
Оцените статью
Tutorial requirements
Requirements Linux
Root privileges No
Difficulty Easy
Est. reading time 5 mintues