# 设置家目录的基路径,所有新建用户的家目录将基于这个路径[root@httpsl /]# useradd -b /test/home/ centos6[root@httpsl /]# cd /test/[root@httpsl test]# ls1.txt home kong nan
[root@httpsl test]# cd home/[root@httpsl home]# ls
centos6
[root@httpsl home]# cd centos6/[root@httpsl centos6]# ls[root@httpsl centos6]# cd /[root@httpsl /]# useradd -b /test/home/ -m centos7[root@httpsl /]# cd /test/home/[root@httpsl home]# ls
centos6 centos7
[root@httpsl home]# cd centos7[root@httpsl centos7]# ls[root@httpsl centos7]# cd /
# 创建用户,并设置用户过期时间[root@httpsl /]# useradd --expiredate 2024-03-27 centos8[root@httpsl /]# id centos8uid=1008(centos8)gid=1010(centos8)groups=1010(centos8)[root@httpsl /]# getent passwd centos8
centos8:x:1008:1010::/home/centos8:/bin/bash
[root@httpsl /]# chage -l centos8
Last password change : Mar 26, 2024
Password expires : never
Password inactive : never
Account expires : Mar 27, 2024
Minimum number of days between password change :0
Maximum number of days between password change :99999
Number of days of warning before password expires :7[root@httpsl /]# passwd -S centos8
centos8 LK 2024-03-26 0999997-1(Password locked.)# 注释:# Last password change:用户最后一次更改密码的日期# Password expires:表示用户密码的过期时间# Password inactive:表示密码处于非活动状态的时间段# Account expires:表示用户账户的过期时间# Minimum number of days between password change:指的是用户可以在上一次更改密码后再次更改密码所需等待的最短天数# Maximum number of days between password change:指的是用户可以在上一次更改密码后再次更改密码的最大天数 # Number of days of warning before password expires:指在密码即将过期前给用户的警告天数
# 替换用户附属组[root@httpsl /]# usermod -G ceshi,ceshi1 kali[root@httpsl /]# getent passwd kali
kali:x:500:0::/test/home//kali:/bin/bash
[root@httpsl /]# id kaliuid=500(kali)gid=0(root)groups=0(root),1003(ceshi),1004(ceshi1)
# 锁定用户,使其无法登录[root@httpsl /]# usermod -L kali
# 解锁用户[root@httpsl /]# usermod -U kali
# 添加用户附属组[root@httpsl /]# usermod -a -G ceshi2 kali[root@httpsl /]# id kaliuid=500(kali)gid=0(root)groups=0(root),1003(ceshi),1004(ceshi1),1005(ceshi2)
# 修改用户主目录[root@httpsl /]# usermod -d /test/home/ kali
(4.)passwd - 管理用户密码
# 设置用户下次登录必须修改密码[root@httpsl ~]# passwd -e kali
Expiring password for user kali.
passwd: Success
# 这是登录的kali用户
You are required to change your password immediately (root enforced)
Last login: Wed Mar 2710:49:30 2024 from 47.96.60.213
Welcome to Alibaba Cloud Elastic Compute Service !
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user kali.
Changing password for kali.
(current) UNIX password:
# 显示密码的状态信息[root@httpsl ~]# passwd -S kali
kali PS 2024-03-27 0999997-1(Password set, SHA512 crypt.)
# 删除用户密码[root@httpsl ~]# passwd -d kali
Removing password for user kali.
passwd: Success
# 显示活动和非活动内页的数量[root@httpsl ~]# vmstat -a
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free inact active si so bi bo in cs us sy id wa st
100880076450568273804001490120010000# 注释:# procs:表示系统进程信息,包括运行、睡眠、停止等状态的进程数目# memory:表示内存使用情况,包括实际内存使用、空闲内存、缓冲区使用和缓存使用等信息# swap:表示交换空间的使用情况,包括交换空间的总量、已用量、空闲量等信息# io:表示I/O设备的负载情况,包括每秒的I/O传输次数(tps)、每秒读取的数据量、每秒写入的数据量等# system:表示系统级统计信息,包括中断的次数、上下文切换的次数等# cpu:表示CPU利用率的统计信息,包括用户态CPU时间、内核态CPU时间、空闲时间等
# 显示 slab 信息,即内核数据结构的缓存信息[root@httpsl ~]# vmstat -m
Cache Num Total Size Pages
ext4_groupinfo_4k 33033013630
ext4_inode_cache 6103961056102416
ext4_xattr 92928846
ext4_free_data 1921926464
ext4_allocation_context 646412832
ext4_io_end 6166167256
ext4_extent_status 219302193040102
jbd2_journal_handle 1701704885
Cache Num Total Size Pages
# 头信息仅显示一次,之后只显示变化的数值(每秒更新一次)[root@httpsl ~]# vmstat -n 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2008799601323366671680014911400100000008794081323446671960007621043694339500000879376132344667248000021403709429500000879544132352667200000842103368532950000087956413235266722000001710327301990000087956413235266722000001675324200100000008795641323526672200000171133240010000000879564132352667220000017013294001000000087956413235266722000001681326310100000008795641323566672200002817013282019900
# 以表格方式显示事件计数器和内存状态[root@httpsl ~]# vmstat -s1798728 K total memory
119540 K used memory
274164 K active memory
450752 K inactive memory
879568 K free memory
132396 K buffer memory
667224 K swap cache
0 K total swap
0 K used swap
0 K free swap
50372 non-nice user cpu ticks
265nice user cpu ticks
29626 system cpu ticks
39306548 idle cpu ticks
3891 IO-wait cpu ticks
0 IRQ cpu ticks
181 softirq cpu ticks
0 stolen cpu ticks
305036 pages paged in1469560 pages paged out
0 pages swapped in0 pages swapped out
336492766 interrupts
649986523 CPU context switches
1711341032 boot time178171 forks
# 报告磁盘状态[root@httpsl ~]# vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
total merged sectors ms total merged sectors ms cur sec
vda 2287234610073858321369755624329416802334824053# 注释:# disk:表示磁盘的名称或标识符# reads:表示磁盘每秒的读操作次数,即每秒从磁盘读取的次数# writes:表示磁盘每秒的写操作次数,即每秒向磁盘写入的次数
(5.)uname - 显示系统信息
# 显示系统信息[root@httpsl ~]# uname -a
Linux httpsl 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
# 以字节显示内存使用情况[root@httpsl ~]# free -b
total used free shared buff/cache available
Mem: 18418974721242767368966676485079048209530881525469184
Swap: 000# 注释:# Total:表示系统的总的可用物理内存大小# Used:表示已被使用的物理内存大小,这包括了被缓冲区(Buffer)和缓存(Cache)占用的部分# Free:表示还有多少物理内存是完全没有被动用过的,即可供直接分配使用的空闲内存量# Shared:表示被共享使用的物理内存大小,即多个进程共享的内存量# Buff/Cache:表示被操作系统的缓冲区(Buffer)和缓存(Cache)占用的物理内存大小# Available:表示还可以被应用程序使用的物理内存大小,它考虑了缓冲区和缓存中的内存,比 free 更真实地反映了可用于启动新应用程序而无需交换出的内存数量
# 以KB显示内存使用情况[root@httpsl ~]# free -k
total used free shared buff/cache available
Mem: 17987281213968755524968017801489684
Swap: 000
# 以MB显示内存使用情况[root@httpsl ~]# free -m
total used free shared buff/cache available
Mem: 175611885507831454
Swap: 000
# 以GB显示内存使用情况[root@httpsl ~]# free -g
total used free shared buff/cache available
Mem: 100001
Swap: 000
# 以简单的方式显示内存使用情况[root@httpsl ~]# free -h
total used free shared buff/cache available
Mem: 1.7G 118M 854M 496K 783M 1.4G
Swap: 0B 0B 0B
(9.)shutdown - 关机或重启
# 设置10分钟后关机[root@httpsl ~]# shutdown -h +10
Shutdown scheduled for Wed 2024-03-27 20:29:02 CST, use 'shutdown -c' to cancel.
[root@httpsl ~]#
Broadcast message from root@centos (Wed 2024-03-27 20:19:02 CST):
The system is going down for power-off at Wed 2024-03-27 20:29:02 CST!
# 取消定时关机[root@httpsl ~]# shutdown -c
Broadcast message from root@centos (Wed 2024-03-27 20:19:43 CST):
The system shutdown has been cancelled at Wed 2024-03-27 20:20:43 CST!