Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view user names and other information in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to view the user name and other information in Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

1) use the id command

Id stands for identity identity. It outputs real and valid user and group ID. You can also output user and group information for a specified user or current user.

# id daygeekuid=1000 (daygeek) gid=1000 (daygeek) groups=1000 (daygeek), 4 (adm), 24 (cdrom), 27 (sudo), 30 (dip), 46 (plugdev), 118 (lpadmin), 128 (sambashare)

Here are the details of the above output:

Uid (1000/daygeek): it displays the user ID and user name

Gid (1000/daygeek): it displays the user's group ID and name

Groups: it displays the user's additional group ID and name

2) use the getent command

The getent command displays entries in databases supported by Name Service Switch libraries, which are configured in / etc/nsswitch.conf.

The getent command displays user details similar to the / etc/passwd file, which puts the details of each user on one line and contains seven fields.

# getent passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/ Shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinmagesh:x:502:503:2g Admin-Magesh M:/home/magesh:/bin/bashthanu:x:503:504:2g Editor-Thanisha M:/home/thanu:/bin/bashsudha:x:504:505:2g Editor-Sudha M:/home/sudha:/bin/bash

Here are the details about the seven fields:

Magesh:x:502:503:2g Admin-Magesh M:/home/magesh:/bin/bash

Username (magesh): user name that has been created. The character length should be between 1 and 32.

Password (x): this indicates that the encrypted password is stored in the / etc/shadow file.

User ID (UID-502): it represents the user ID (UID), and each user should contain * UID. UID (0-Zero) reserved for root,UID (1-99) is reserved for system users, and UID (100,999) is reserved for system accounts / groups.

Group ID (GID-503): it represents the group ID (GID), and each group should contain the GID of * *, which is stored in the / etc/group file.

User ID Info (2g Admin-Magesh M): it represents a command field. This field can be used to describe user information.

Home Directory (/ home/magesh): it represents the user's home directory.

Shell (/ bin/bash): it represents the user's bash shell.

If you only want to display the user name in the output of the getent command, use the following command format:

# getent passwd | cut-d:-f1rootbindaemonadmlpsyncshutdownhaltmailuucpoperatorgamesgophermageshthanusudha

Display only the user's home directory, using the following command format:

# getent passwd | grep'/ home' | cut-d:-f1centosprakashmageshthanusudha3) use the / etc/passwd file

/ etc/passwd is a text file that contains the information necessary for each user to log in to the Linux system. It maintains useful information about the user, such as user name, password, user ID, group ID, user ID information, home directory and shell. The / etc/passwd file puts the details of each user on one line and contains seven fields, as shown below:

# cat / etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin: / sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinmagesh:x:502:503:2g Admin-Magesh M:/home/magesh:/bin/bashthanu:x:503:504:2g Editor-Thanisha M:/home/thanu:/bin/bashsudha:x:504:505:2g Editor-Sudha M:/home/sudha:/bin/bash

The following are the details of the seven fields.

Magesh:x:502:503:2g Admin-Magesh M:/home/magesh:/bin/bash

Field information is the same as above.

If you only want to display the user name in the / etc/passwd file, use the following format:

# cut-d:-F1 / etc/passwdrootbindaemonadmlpsyncshutdownhaltmailuucpoperatorgamesgophermageshthanusudha

Only the user's home directory is displayed, using the following format:

# cat / etc/passwd | grep'/ home' | cut-d:-f1centosprakashmageshthanusudha4) use the finger command

The finger command displays information about the system user. It displays the user's real name, terminal name and write status (if there is no write permission, then the * after the terminal name), idle time and login time.

# finger mageshLogin: magesh Name: 2g Admin-Magesh MDirectory: / home/magesh Shell: / bin/bashLast login Tue Jul 17 22:46 (EDT) on pts/2 from 103.5.134.167No mail.No Plan.

The following are the details of the above output:

Login: user name

Name: additional / additional information about the user

Directory: information of the user's home directory

Shell: user's shell information

LAST-LOGIN: last login date and other information

5) use the lslogins command

It displays information about users known to the system. By default, it lists information for all users in the system.

The lslogins usage program was inspired by the logins utility, which first appeared in FreeBSD 4.10.

# lslogins-uUID USER PWD-LOCK PWD-DENY LAST-LOGIN GECOS 0 root 00 00:17:28 root500 centos 01 Cloud User501 prakash 00 Apr12/04:08 2018 Unip 04 Jul17/22:46 12502 magesh 00 Jul17/22:46 2g Admin-Magesh M503 thanu 00 Jul18/00:40 2g Editor-Thanisha M504 sudha 00 Jul18/01:18 2g Editor-Sudha M

The following are the details of the above output:

UID: user id

USER: user name

PWD-LOCK: password is set but locked

PWD-DENY: whether the login password is disabled

LAST-LOGIN: date of last login

GECOS: additional information about the user

6) use the compgen command

Compgen is a bash built-in command that displays all available commands, aliases, and functions. LCTT: its-u parameter can list users in the system. )

# compgen-urootbindaemonadmlpsyncshutdownhaltmailuucpoperatorgamesgophermageshthanusudha Thank you for reading this article carefully. I hope the article "how to View user names and other Information in Linux" shared by the editor will be helpful to you. At the same time, I hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report