#Bash 的 lslogins 命令
lslogins [OPTION]... [USERNAME]
功能
列出系统中的用户信息。
类型
可执行文件(/usr/bin/lslogins),属于 util-linux。
参数
OPTION选项:-a,--acc-expiration- 显示上次修改密码的时间以及密码过期时间--btmp-file path- 指定 btmp 文件的路径-c,--colon-separate- 使用冒号作为用户之间的分隔符-e,--export- 以NAME=VALUE的格式输出-f,--failed- 显示用户最近一次登录失败的相关信息-G,--supp-groups- 显示用户的 补充组 信息-g,--groups=groups- 仅显示属于特定组的用户信息;多个组用逗号分隔-L,--last- 显示包含用户上次登录会话的信息-l,--logins=logins- 仅显示特定登录名的用户信息;多个登录名用逗号分隔-n,--newline- 每条信息单独显示一行--noheadings- 不显示标题行(列名)--notruncate- 不截断输出-o,--output list- 只输出指定的列--output-all- 输出所有可用的列-p,--pwd- 显示与密码登录相关的信息-r,--raw- 以原始格式输出-s,--system-accs- 显示系统账户--time-format type- 指定时间格式:short,full或iso;默认为short-u,--user-accs- 显示用户账户--wtmp-file path- 指定 wtmp 文件的路径--lastlog path- 指定 lastlog 的路径-y,--shell- 使列名只包含 SHELL 变量标识符允许的字符-Z,--context- 显示用户的安全上下文-z,--print0- 以空字符(\0)作为行的结尾,而不是换行符(\n)-h,--help- 显示帮助-V,--version- 显示版本
USERNAME- 指定要查看的用户
#列名
| 列名 | 说明 |
|---|---|
| USER | 用户名 |
| UID | 用户 ID |
| GECOS | 完整用户名 |
| HOMEDIR | 用户的主目录 |
| SHELL | 用户的登录 SHELL |
| NOLOGIN | 被 nologin 或 pam_nologin 禁止登录 |
| PWD-LOCK | 密码已设置,但被锁定 |
| PWD-EMPTY | 未设置密码 |
| PWD-DENY | 已禁止密码登录 |
| PWD-METHOD | 密码加密方法 |
| GROUP | 主要组名 |
| GID | 主要组 ID |
| SUPP-GROUPS | 补充组名 |
| SUPP-GIDS | 补充组 ID |
| LAST-LOGIN | 上次登录日期 |
| LAST-TTY | 上次使用的 TTY |
| LAST-HOSTNAME | 上次会话的主机名 |
| FAILED-LOGIN | 上次登录失败的日期 |
| FAILED-TTY | 上次登录失败的 TTY |
| HUSHED | 用户静音设置 |
| PWD-WARN | 密码过期警告剩余天数 |
| PWD-CHANGE | 上次更改密码的日期 |
| PWD-MIN | 两次修改密码之间最少需要间隔的天数 |
| PWD-MAX | 密码最多可保持不变的天数 |
| PWD-EXPIR | 密码过期日期 |
| CONTEXT | 用户安全上下文 |
| PROC | 用户运行的进程数 |
#示例
$ lslogins
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 201 0 0 root
1 daemon 0 daemon
2 bin 0 bin
3 sys 0 sys
4 sync 0 sync
5 games 0 games
6 man 0 man
7 lp 0 lp
8 mail 0 mail
9 news 0 news
...
#推荐阅读
#手册
LSLOGINS(1) User Commands LSLOGINS(1)
NAME
lslogins - display information about known users in the system
SYNOPSIS
lslogins [options] [-s|-u[=UID]] [-g groups] [-l logins] [username]
DESCRIPTION
Examine the wtmp and btmp logs, /etc/shadow (if necessary) and /passwd
and output the desired data.
The optional argument username forces lslogins to print all available
details about the specified user only. In this case the output format
is different than in case of -l or -g and unknown is username reported
as an error.
The default action is to list info about all the users in the system.
OPTIONS
Mandatory arguments to long options are mandatory for short options
too.
-a, --acc-expiration
Display data about the date of last password change and the account
expiration date (see shadow(5) for more info). (Requires root
privileges.)
--btmp-file path
Alternate path for btmp.
-c, --colon-separate
Separate info about each user with a colon instead of a newline.
-e, --export
Output data in the format of NAME=VALUE. See also option --shell.
-f, --failed
Display data about the users' last failed login attempts.
-G, --supp-groups
Show information about supplementary groups.
-g, --groups=groups
Only show data of users belonging to groups. More than one group
may be specified; the list has to be comma-separated. Unknown group
names are ignored.
Note that the relation between user and group may be invisible for
the primary group if the user is not explicitly specified as group
member (e.g., in /etc/group). If the command lslogins scans for
groups then it uses the groups database only, and the user database
with primary GID is not used at all.
-L, --last
Display data containing information about the users' last login
sessions.
-l, --logins=logins
Only show data of users with a login specified in logins (user
names or user IDs). More than one login may be specified; the list
has to be comma-separated. Unknown login names are ignored.
-n, --newline
Display each piece of information on a separate line.
--noheadings
Do not print a header line.
--notruncate
Don’t truncate output.
-o, --output list
Specify which output columns to print. The default list of columns
may be extended if list is specified in the format +list.
--output-all
Output all available columns. --help to get a list of all supported
columns.
-p, --pwd
Display information related to login by password (see also -afL).
-r, --raw
Raw output (no columnation).
-s, --system-accs
Show system accounts. These are by default all accounts with a UID
between 101 and 999 (inclusive), with the exception of either
nobody or nfsnobody (UID 65534). This hardcoded default may be
overwritten by parameters SYS_UID_MIN and SYS_UID_MAX in the file
/etc/login.defs.
--time-format type
Display dates in short, full or iso format. The default is short,
this time format is designed to be space efficient and human
readable.
-u, --user-accs
Show user accounts. These are by default all accounts with UID
above 1000 (inclusive), with the exception of either nobody or
nfsnobody (UID 65534). This hardcoded default maybe overwritten by
parameters UID_MIN and UID_MAX in the file /etc/login.defs.
-h, --help
Display help text and exit.
-V, --version
Print version and exit.
--wtmp-file path
Alternate path for wtmp.
--lastlog path
Alternate path for lastlog(8).
-y, --shell
The column name will be modified to contain only characters allowed
for shell variable identifiers. This is usable, for example, with
--export. Note that this feature has been automatically enabled for
--export in version 2.37, but due to compatibility issues, now it’s
necessary to request this behavior by --shell.
-Z, --context
Display the users' security context.
-z, --print0
Delimit user entries with a nul character, instead of a newline.
EXIT STATUS
0
if OK,
1
if incorrect arguments specified,
2
if a serious error occurs (e.g., a corrupt log).
NOTES
The default UID thresholds are read from /etc/login.defs.
Password status
Multiple fields describe password status.
"Password is locked"
The password is prefixed by '!!', and the user cannot login
although the password is set or empty. This is common for new
accounts without a set password.
"Password not required (empty)"
The password is not set (hash is missing); this is common for
locked system accounts. Not requiring a password does not mean the
user can log-in without a password. It depends on the password
"lock" status.
"Login by password disabled"
'yes' means that there is no valid password. The password hash is
missing, or the hash method is unknown or contains invalid chars.
HISTORY
The lslogins utility is inspired by the logins utility, which first
appeared in FreeBSD 4.10.
AUTHORS
Ondrej Oprala <ooprala@redhat.com>, Karel Zak <kzak@redhat.com>
SEE ALSO
group(5), passwd(5), shadow(5), utmp(5)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The lslogins command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-11-30 LSLOGINS(1)