useradd、usermod、userdel都是系统管理员常用的关于用户的命令。那么普通用户除了可以修改自身的密码之外,可以修改其它的数据吗?本问就简单介绍。
【目录】
一 id命令使用
二 finger命令的使用
三 chfn命令参数介绍
四 chsh命令参数介绍
一 id命令使用
1.1 参数介绍
[root@achao achao]# id --help
Usage: id [OPTION]... [USER]
Print user and group information for the specified USER,
or (when USER omitted) for the current user.
-a ignore, for compatibility with other versions
-Z, --context print only the security context of the current user
-g, --group print only the effective group ID
-G, --groups print all group IDs
-n, --name print a name instead of a number, for -ugG
-r, --real print the real ID instead of the effective ID, with -ugG
-u, --user print only the effective user ID
-z, --zero delimit entries with NUL characters, not whitespace;
not permitted in default format
--help display this help and exit
--version output version information and exit
Without any OPTION, print some useful set of identified information.
复制
1.2 参数使用
#查看当前用户的id信息
[root@achao achao]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
#UID的值
[root@achao achao]# id -u
0
#GID的值
[root@achao achao]# id -g
0
#判断系统中是否存在该用户
[root@achao achao]# id achao
id: achao: no such user
复制
特别说明id查看出来下边的这些信息是有关SELinux相关的,前边的文章中做过介绍,感兴趣的可以关注并在历史中查看。此处不在展开。
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
复制
二 finger命令的使用
2.1 finger命令安装
发现系统中没有finger命令,那么就安装它呗!
[root@achao achao]# which finger
/usr/bin/which: no finger in (/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/root/bin)
[root@achao achao]# yum -y install finger
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package finger.x86_64 0:0.17-52.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================
Installing:
finger x86_64 0.17-52.el7 base 25 k
Transaction Summary
=============================================================================================================================================================================
Install 1 Package
Total download size: 25 k
Installed size: 32 k
Downloading packages:
finger-0.17-52.el7.x86_64.rpm | 25 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : finger-0.17-52.el7.x86_64 1/1
Verifying : finger-0.17-52.el7.x86_64 1/1
Installed:
finger.x86_64 0:0.17-52.el7
Complete!
复制
这里介绍一下为什么系统不内置这个命令呢,因为可以直接操作/etc/passwd文件中的内容,危险,因此新一点的版本中将此命令裁剪掉,需要使用时自行安装。
2.2 finger命令的参数介绍
FINGER(1) BSD General Commands Manual FINGER(1)
NAME
finger — user information lookup program
SYNOPSIS
finger [-lmsp] [user ...] [user@host ...]
DESCRIPTION
The finger displays information about the system users.
Options are:
-s Finger displays the user's login name, real name, terminal name and write status (as a ``*'' after the terminal name if write permission is denied), idle
time, login time, office location and office phone number.
Login time is displayed as month, day, hours and minutes, unless more than six months ago, in which case the year is displayed rather than the hours and min‐
utes.
Unknown devices as well as nonexistent idle and login times are displayed as single asterisks.
-l Produces a multi-line format displaying all of the information described for the -s option as well as the user's home directory, home phone number, login
shell, mail status, and the contents of the files “.plan”, “.project”, “.pgpkey” and “.forward” from the user's home directory.
Phone numbers specified as eleven digits are printed as ``+N-NNN-NNN-NNNN''. Numbers specified as ten or seven digits are printed as the appropriate subset
of that string. Numbers specified as five digits are printed as ``xN-NNNN''. Numbers specified as four digits are printed as ``xNNNN''.
If write permission is denied to the device, the phrase ``(messages off)'' is appended to the line containing the device name. One entry per user is dis‐
played with the -l option; if a user is logged on multiple times, terminal information is repeated once per login.
Mail status is shown as ``No Mail.'' if there is no mail at all, ``Mail last read DDD MMM ## HH:MM YYYY (TZ)'' if the person has looked at their mailbox
since new mail arriving, or ``New mail received ...'', `` Unread since ...'' if they have new mail.
-p Prevents the -l option of finger from displaying the contents of the “.plan”, “.project” and “.pgpkey” files.
-m Prevent matching of user names. User is usually a login name; however, matching will also be done on the users' real names, unless the -m option is sup‐
plied. All name matching performed by finger is case insensitive.
复制
2.3 finger命令常用的几种方式
[admin@achao ~]$ id
uid=1000(admin) gid=1000(admin) groups=1000(admin),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[admin@achao ~]$ finger -s admin
Login Name Tty Idle Login Time Office Office Phone Host
admin admin pts/0 * Aug 11 14:24
#列出目前在系统上边登录的使用者与登录时间
[admin@achao ~]$ finger
Login Name Tty Idle Login Time Office Office Phone Host
root root *:0 Jul 13 14:15 (:0)
root root pts/0 Aug 11 14:22
#列出admin用户的详细信息
[admin@achao ~]$ finger admin
Login: admin Name: admin
Directory: /home/admin Shell: /bin/bash
Last login Sun Aug 11 14:24 (CST) on pts/0
No mail.
No Plan.
复制
三 chfn命令参数介绍
[admin@achao ~]$ chfn --help
Usage:
chfn [options] [username]
Options:
-f, --full-name <full-name> real name
-o, --office <office> office number
-p, --office-phone <phone> office phone number
-h, --home-phone <phone> home phone number
-u, --help display this help and exit
-v, --version output version information and exit
For more details see chfn(1).
复制
我们在finger命令查看当前用户信息的时候出现过 Office Office Phone Host的关键词,这是干什么的呢?在chfn中的参数就给出解释。
[admin@achao ~]$ chfn
Changing finger information for admin.
Name [admin]: huohuazi1016
Office []: 15619303358
Office Phone []: 15619303358
Home Phone []: 15619303358
Password: #输入当前用户的密码
Finger information changed.
复制
接下来进行查看
[admin@achao ~]$ grep admin /etc/passwd
admin:x:1000:1000:huohuazi1016,15619303358,15619303358,15619303358:/home/admin:/bin/bash
[admin@achao ~]$ finger admin
Login: admin Name: huohuazi1016
Directory: /home/admin Shell: /bin/bash
Office: 15619303358, +1-561-930-3358 Home Phone: +1-561-930-3358
Last login Sun Aug 11 14:24 (CST) on pts/0
No mail.
No Plan.
复制
个人觉得这个命令好像没有什么有用的地方,各位大佬浏览一下就好。在现实的生产环境中我没有用过的。
四 chsh命令参数介绍
[admin@achao ~]$ chsh --help
Usage:
chsh [options] [username]
Options:
-s, --shell <shell> specify login shell
-l, --list-shells print list of shells and exit
-u, --help display this help and exit
-v, --version output version information and exit
For more details see chsh(1).
复制
4.1 chsh参数-l的使用
#列出目前系统上可用的shell
[admin@achao ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin #合法不可登录的shell
/bin/tcsh
/bin/csh
#上边列出的信息也就是/etc/shells中的内容
[admin@achao ~]$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
复制
4.2 chsh参数-s的使用
[admin@achao ~]$ chsh -s /bin/csh
Changing shell for admin.
Password: #输入admin的密码进行确认
Shell changed.
[admin@achao ~]$ grep admin /etc/passwd
admin:x:1000:1000:huohuazi1016,15619303358,15619303358,15619303358:/home/admin:/bin/csh
[admin@achao ~]$ finger admin
Login: admin Name: huohuazi1016
Directory: /home/admin Shell: /bin/csh
Office: 15619303358, +1-561-930-3358 Home Phone: +1-561-930-3358
Last login Sun Aug 11 14:24 (CST) on pts/0
No mail.
No Plan.
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
OB 企业版单机版探秘——安装部署
数据库技术闲谈
61次阅读
2025-04-10 11:53:00
使用 MySQLShell 9.2.0 进行数据增量导出
阮胜昌
36次阅读
2025-04-01 17:39:38
使用lftp实现断点续传的功能
zayki
29次阅读
2025-04-22 17:31:54
mysql8 mgr 脚本
大圣11
28次阅读
2025-04-07 16:23:24
严防脚本泄露!教你几个让 Shell 脚本仅自己可见的加密技巧
小周的数据库进阶之路
24次阅读
2025-04-25 10:10:49
在 Shell 中按当前日期创建文件夹
运维笔谈
10次阅读
2025-04-11 07:03:20
【实战】一招搞定Shell调度!DolphinScheduler+ProcessBuilder超详细教程
海豚调度
2次阅读
2025-04-28 10:22:19