Linux文件操作与用户管理

一、文件的移动、重命名、复制

移动、重命名
命令:mv

1.1 移动

[root@localhost xiaoming]# ls
1.txt  2.txt  3.txt  a  root.txt  xiaoming  xiaoming.txt
[root@localhost xiaoming]# cd ..
[root@localhost yuanyi]# ls
xiaohua  xiaoming
[root@localhost yuanyi]# cd xiaohua 
[root@localhost xiaohua]# ls
[root@localhost xiaohua]# cd ..
[root@localhost yuanyi]# cd xiaoming/
[root@localhost xiaoming]# mv *.txt /yuanyi/xiaohua/  #把所有后缀为.txt的文件都移到/yuanyi/xiaohua
[root@localhost xiaoming]# ls
a  xiaoming
[root@localhost xiaoming]# cd ..
[root@localhost yuanyi]# cd xiaohua
[root@localhost xiaohua]# ls
1.txt  2.txt  3.txt  root.txt  xiaoming.txt

1.2 重命名

[root@localhost xiaohua]# ls
1.txt  2.txt  3.txt  root.txt  xiaoming.txt
[root@localhost xiaohua]# mv 1.txt 111.txt
[root@localhost xiaohua]# ls
111.txt  2.txt  3.txt  root.txt  xiaoming.txt

1.3 批量的移动

[root@localhost xiaoming]# ls
a  aa  b  bb  xiaoming
[root@localhost xiaoming]# mv a aa b bb xiaoming(文件夹名)
[root@localhost xiaoming]# ls
xiaoming
[root@localhost xiaoming]# cd xiaoming/
[root@localhost xiaoming]# ls
a  aa  b  bb
[root@localhost xiaoming]# mv -t /yuanyi/xiaohua/ a aa b bb #-t 先给文件名再给要移动的文档名
mv:是否覆盖"/yuanyi/xiaohua/a"? y
[root@localhost xiaoming]# ls
[root@localhost xiaoming]# cd ..
[root@localhost xiaoming]# cd ..
[root@localhost yuanyi]# cd xiaohua
[root@localhost xiaohua]# ls
111.txt  2.txt  3.txt  a  aa  b  bb  root.txt  xiaoming.txt

1.4 询问是否覆盖:

-f:强制覆盖

	 [root@localhost xiaohua]# ls
    111.txt  2.txt  3.txt  a  aa  b  bb  root.txt  xiaoming.txt
    [root@localhost xiaohua]# mv 2.txt 3.txt   #默认会询问
    mv:是否覆盖"3.txt"? y
    [root@localhost xiaohua]# ls
    111.txt  3.txt  a  aa  b  bb  root.txt  xiaoming.txt
    [root@localhost xiaohua]# mv -i 111.txt 3.txt  #i 开启询问 即默认状态;
    mv:是否覆盖"3.txt"? n
    [root@localhost xiaohua]# ls
    111.txt  3.txt  a  aa  b  bb  root.txt  xiaoming.txt
    [root@localhost xiaohua]# mv -f 111.txt 3.txt  #f 强制覆盖,不进行询问;
    [root@localhost xiaohua]# ls
    3.txt  a  aa  b  bb  root.txt  xiaoming.txt

1.5 目录的移动

[root@localhost xiaohua]# ls
3.txt  a  aa  b  bb  c  cc  d  dd  root.txt  xiaoming.txt  yy
[root@localhost xiaohua]# mv c cc d dd yy
[root@localhost xiaohua]# ls
3.txt  a  aa  b  bb  root.txt  xiaoming.txt  yy
[root@localhost xiaohua]# cd yy
[root@localhost yy]# ls
c  cc  d  dd
[root@localhost yy]# mv -t c cc d dd
[root@localhost yy]# ls
c
[root@localhost yy]# cd c
[root@localhost c]# ls
cc  d  dd

在这里插入图片描述

1.6 移动当前文件下所有内容到上一级目录

[root@localhost yy]# ls
c
[root@localhost yy]# cd c
[root@localhost c]# ls
cc  d  dd
[root@localhost c]# mv * ..  #* 代表所有文件 ..代表上一级目录
[root@localhost c]# ls
[root@localhost c]# cd ..
[root@localhost yy]# ls
c  cc  d  dd

在这里插入图片描述

1.7文件被覆盖前做个简单备份

[root@localhost c]# mv 1.txt -b 2.txt
mv:是否覆盖"2.txt"? y
[root@localhost c]# ls
2.txt  2.txt~  b
[root@localhost c]# cat 2.txt
this is 1.txt
[root@localhost c]# cat 2.txt~
this is 2.txt

在这里插入图片描述

1.8 复制文件或目录

拷目录
[root@localhost yuanyi]# cp -r(命令) xiaohua(源地址) xiaoming/(目的地址)
在这里插入图片描述

二、账号的管理

2.1 w命令参数查看用户登录信息

[root@localhost ~]# w
11:51:18(当前系统时间) up 3:05,(当前系统开始运行的时间) 3 users,(当前系统登录用户的总数) load average: 0.00, 0.00, 0.00(1,5,10分钟内的负载程度)
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 :0 08:46 3:05m 6.92s 6.92s /usr/bin/Xorg :0 -
root pts/0 172.16.11.31 10:56 30:16 0.10s 0.10s -bash
root pts/1 172.16.11.31 11:28 0.00s 0.15s 0.06s w

USER:显示登录用户账号,用户重复登录,该账号会重复出现;
TTY:用户登录所有的终端;
FROM:用户从何处登录;
LOGIN@:表示登录进入系统的时间;
IDLE:用户空闲时间,从用户上一次任务结束后开始计时;
JCPU:以终端代号来区分,表示在这段时间内,所有与该终端相关的进程任务所消耗CPU的时间;
PCPU:指WHAT任务执行后消耗CPU的时间;
WHA:表示当前执行的任务;

负载:数值越小越好。

2.2 Who命令:显示当前登录系统的用户

who命令:显示当前登录系统的用户。

[root@localhost ~]# who 
root     tty1         2020-08-13 08:46 (:0)
root     pts/1        2020-08-13 11:28 (172.16.11.31)
root     pts/2        2020-08-13 14:26 (172.16.11.31)

2.3 who命令的参数介绍

[root@localhost ~]# who -r		#运行级别
         运行级别 5 2020-08-13 08:45
[root@localhost ~]# who -H		#添加标题
名称   线路       时间           备注
root     tty1         2020-08-13 08:46 (:0)
root     pts/1        2020-08-13 11:28 (172.16.11.31)
root     pts/2        2020-08-13 14:26 (172.16.11.31)
[root@localhost ~]# who -q		#对当前用户登录用户数量统计数
root root root
# 用户数=3
[root@localhost ~]# who -u -H		#(-u打印空闲时间和进程号)
名称   线路       时间           空闲  进程号 备注
root     tty1         2020-08-13 08:46  旧的        2459 (:0)
root     pts/1        2020-08-13 11:28 04:16        3647 (172.16.11.31)
root     pts/2        2020-08-13 14:26   .          3982 (172.16.11.31)
[root@localhost ~]# who -l			#显示系统登录相关的进程及终端信息
登录   tty2         2020-08-13 08:45              2279 id=2
登录   tty3         2020-08-13 08:46              2281 id=3
登录   tty4         2020-08-13 08:46              2283 id=4
登录   tty5         2020-08-13 08:46              2288 id=5
登录   tty6         2020-08-13 08:46              2291 id=6
[root@localhost ~]# who -a			#显示系统所有登录相关的进程及终端信息
           系统引导 2020-08-13 08:45
           运行级别 5 2020-08-13 08:45
登录     tty2         2020-08-13 08:45              2279 id=2
登录     tty3         2020-08-13 08:46              2281 id=3
登录     tty4         2020-08-13 08:46              2283 id=4
登录     tty5         2020-08-13 08:46              2288 id=5
登录     tty6         2020-08-13 08:46              2291 id=6
root     + tty1         2020-08-13 08:46  旧的        2459 (:0)
           pts/0        2020-08-13 14:48              3489 id=ts/0  终端=0 退出=0
root     + pts/1        2020-08-13 11:28 04:16        3647 (172.16.11.31)
root     + pts/2        2020-08-13 14:26   .          3982 (172.16.11.31)
[root@localhost ~]# who -lH		#显示用户登录来源
名称   线路       时间           空闲  进程号 备注
登录   tty2         2020-08-13 08:45              2279 id=2
登录   tty3         2020-08-13 08:46              2281 id=3
登录   tty4         2020-08-13 08:46              2283 id=4
登录   tty5         2020-08-13 08:46              2288 id=5
登录   tty6         2020-08-13 08:46              2291 id=6
[root@localhost ~]# who -TH 	#显示终端属性
名称     线路       时间           备注
root     + tty1         2020-08-13 08:46 (:0)
root     + pts/1        2020-08-13 11:28 (172.16.11.31)
root     + pts/2        2020-08-13 14:26 (172.16.11.31)
[root@localhost ~]# echo "hello">tty1
[root@localhost ~]# who -TH
名称     线路       时间           备注
root     + tty1         2020-08-13 08:46 (:0)
root     + pts/1        2020-08-13 11:28 (172.16.11.31)
root     + pts/2        2020-08-13 14:26 (172.16.11.31)

2.4 踢除Linux登录的用户

应用:把当前的登录用户移除掉

[root@localhost ~]# who -u -H
名称   线路       时间           空闲  进程号 备注
root     tty1         2020-08-13 08:46  旧的        2459 (:0)
root     pts/1        2020-08-13 11:28 04:26        3647 (172.16.11.31)
root     pts/2        2020-08-13 14:26   .          3982 (172.16.11.31)
root     pts/0        2020-08-13 16:16 00:01        4260 (:0.0)
[root@localhost ~]# kill -9 4260
[root@localhost ~]# who -u -H
名称   线路       时间           空闲  进程号 备注
root     tty1         2020-08-13 08:46  旧的        2459 (:0)
root     pts/2        2020-08-13 14:26   .          3982 (172.16.11.31)

2.5 whoami 命令的使用

whoami:当前登录用户是谁。

[root@localhost ~]# whoami
root

2.6 用户的添加及删除

用户的添加:

[root@localhost ~]# useradd xiaowang   #添加新用户
[root@localhost ~]# passwd xiaowang		#给新用户设置密码
更改用户 xiaowang 的密码 。
新的 密码:
无效的密码: 过于简单化/系统化
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
[root@localhost ~]# su - xiaowang
[xiaowang@localhost ~]$ ls
[xiaowang@localhost ~]$ su - root
密码:
[root@localhost ~]# 

用户的删除:

[root@localhost ~]# userdel useradd-g #普通删除,不能删除其家目录及家目录里面的文件以及用户的邮箱
[root@localhost ~]# cat /etc/passwd | grep "useradd-g" #删除成功
useradd-g-G:x:505:503::/home/useradd-g-G:/bin/bash
[root@localhost ~]# cat /etc/passwd
xiaowang:x:503:503::/home/xiaowang:/bin/bash
useradd-g-G:x:505:503::/home/useradd-g-G:/bin/bash
useradd-s:x:506:506::/home/useradd-s:/bin/sh
useradd-c:x:507:507:this is useradd-c:/home/useradd-c:/bin/bash
useradd-d:x:508:508::/useradd-d:/bin/bash
useradd-all:x:999:0:this is useradd-all:/xxxx:/bin/shell
[root@localhost ~]# cat /etc/shadow | grep "useradd-g" #删除成功
useradd-g-G:!!:18487:0:99999:7:::
[root@localhost ~]# cat /etc/group | grep "useradd-g"	#删除成功
xiaoming:x:501:useradd-g-G
xiaohua:x:502:useradd-g-G,useradd-all
[root@localhost ~]# userdel -r useradd-c  #-r 删除用户及其家目录及其文件一起删除及用户的邮箱删除
[root@localhost ~]# cat /etc/group | grep "useradd-c"
[root@localhost ~]# cat /etc/shadow | grep "useradd-c"
[root@localhost ~]# cat /etc/passwd | grep "useradd-c"

在这里插入图片描述

2.7 系统创建用户所做的事件

1. 总结:

1、/etc/passwd 存放用户相关的信息
2、/etc/shadow 存放用户密码信息的
3、/etc/group 存放用户的组的信息
4、/etc/gshadow 存放用户组的密码的信息
5、/etc/login.defs 存放用户全局配置文件(密码的策略)

2. 实际内容:
  1. 当创建一个用户时,系统会自动在家目录增加相应的家目录,并且系统会把/etc/skel里面的用户环境变量cp到所创建的家目录里面去。
[root@localhost ~]# cd /home
[root@localhost home]# ls
xiaohua  xiaoming  xiaowang  yy
[root@localhost home]# cd /etc/skel/
[root@localhost skel]# ls
[root@localhost skel]# ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .gnome2  .mozilla
[root@localhost yy]# cd /home/xiaowang/
[root@localhost xiaowang]# ls
[root@localhost xiaowang]# ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .gnome2  .mozilla
  1. 当创建一个用户时,系统会自动创建一个与用户名相同的组,并且把用户自动添加到这个组里面去。
[root@localhost xiaowang]# id xiaowang #查看用户UID、GID、组;
uid=503(xiaowang) gid=503(xiaowang) 组=503(xiaowang)
  1. 用户相关的配置文件添加这个用户相关记录
[root@localhost xiaowang]# cat /etc/passwd	#用户相关配置文件
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
.......
yy:x:500:500:yuanyi:/home/yy:/bin/bash
xiaoming:x:501:501::/home/xiaoming:/bin/bash
xiaohua:x:502:502::/home/xiaohua:/bin/bash
xiaowang:x:503:503::/home/xiaowang:/bin/bash  #自动添加的相关记录

xiaowang(用户名):x(密码展示符,说明有密码,但不给予显示):503(UID):503(GID):(对用户的描述,默认为空):/home/xiaowang(家目录):/bin/bash(命令解释程序shell :bash:说明可以登录;nologin:说明不能登录使用)
4. 在密码配置文件里添加这个用户的相关记录

[root@localhost xiaowang]# cat /etc/shadow  #密码配置文件
root:$6$s55JknA/dPeUkOdQ$mf3o4Tcz.ng1VtL4uZpHhu6g3D5mjyogP5mDEm9OH..n0yGQMtDJZymiN1JwJizzCh9J6iagKqzDJkoxNozm4.:18484:0:99999:7:::
bin:*:15980:0:99999:7:::
daemon:*:15980:0:99999:7:::
adm:*:15980:0:99999:7:::
lp:*:15980:0:99999:7:::
sync:*:15980:0:99999:7:::
.......
xiaohua:$6$l6x0TI6o$57FMzVOshwsMY0ODP.wOtYtS1BNQyIIs33kejc4T3Im9DXBT7koC5bvq9GtSdiFHnWY71G3afH7MvV8kHA8N00:18486:0:99999:7:::
xiaowang:$6$YKRKyh9X$Eq5e2X5lZbLNZxaBiEmMaiffHrxjGDIk2DXjYhAbeSo0lWDG9BTZ/MnqqRvZJCSaiuVngZQtoqf9.CbHhlcX50:18487:0:99999:7:::

密码属于加密后的样子;
5. 用户组相关配置文件添加这个用户相关组记录

[root@localhost xiaowang]# cat /etc/group
root:x:0:
bin:x:1:bin,daemon
daemon:x:2:bin,daemon
...
xiaohua:x:502:
xiaowang:x:503:
  1. 用户相关的组配置文件添加这个用户记录
[root@localhost xiaowang]# cat /etc/gshadow
root:::
bin:::bin,daemon
daemon:::bin,daemon
...
xiaohua:!::
xiaowang:!::
  1. 目录/etc/skel里面存放的时用户的初始环境变量。
  2. 创建用户策略全局文件。
[root@localhost xiaowang]# cat //etc/login.defs
#
# Please note that the parameters in this configuration file control the
# behavior of the tools from the shadow-utils component. None of these
# tools uses the PAM mechanism, and the utilities that use PAM (such as the
# passwd command) should therefore be configured elsewhere. Refer to
# /etc/pam.d/system-auth for more information.
#

# *REQUIRED*
#   Directory where mailboxes reside, _or_ name of file, relative to the
#   home directory.  If you _do_ define both, MAIL_DIR takes precedence.
#   QMAIL_DIR is for Qmail
#
#QMAIL_DIR	Maildir
MAIL_DIR	/var/spool/mail
#MAIL_FILE	.mail

# Password aging controls:
#
#	PASS_MAX_DAYS	Maximum number of days a password may be used.
#	PASS_MIN_DAYS	Minimum number of days allowed between password changes.
#	PASS_MIN_LEN	Minimum acceptable password length.
#	PASS_WARN_AGE	Number of days warning given before a password expires.
#
PASS_MAX_DAYS	99999
PASS_MIN_DAYS	0
PASS_MIN_LEN	5
PASS_WARN_AGE	7

#
# Min/max values for automatic uid selection in useradd
#
UID_MIN			  500
UID_MAX			60000

#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN			  500
GID_MAX			60000

#
# If defined, this command is run when removing a user.
# It should remove any at/cron/print jobs etc. owned by
# the user to be removed (passed as the first argument).
#
#USERDEL_CMD	/usr/sbin/userdel_local

#
# If useradd should create home directories for users by default
# On RH systems, we do. This option is overridden with the -m flag on
# useradd command line.
#
CREATE_HOME	yes

# The permission mask is initialized to this value. If not specified, 
# the permission mask will be initialized to 022.
UMASK           077

# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes

# Use SHA512 to encrypt password.  ######密码加密方式
ENCRYPT_METHOD SHA512 

Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512

9. 创建用户时同时创建该用户的邮箱及账号(前提是安装了邮件服务)

[root@localhost xiaowang]# cd /var/spool/mail/
[root@localhost mail]# ls
root  rpc  xiaohua  xiaoming  xiaowang  yy

案例:root用户向xiaowang用户发送一封邮件

[root@localhost mail]# mail -s "hello my name is root" xiaowang@localhost
come on xiaowang!!!!EOT  #EOT=ctrl+d:结束内容
[root@localhost mail]# su - xiaowang  
[xiaowang@localhost ~]$ mail	#查看邮件
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/xiaowang": 1 message 1 new
>N  1 root                  Thu Aug 13 16:54  18/657   "hello my name is root"
& 1
Message  1:
From root@localhost.localdomain  Thu Aug 13 16:54:41 2020
Return-Path: <root@localhost.localdomain>
X-Original-To: xiaowang@localhost
Delivered-To: xiaowang@localhost.localdomain
Date: Thu, 13 Aug 2020 16:54:41 +0800
To: xiaowang@localhost.localdomain
Subject: hello my name is root
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: root@localhost.localdomain (root)
Status: R

come on xiaowang!!!!    #成功收到

& 

2.8 useradd的命令参数使用

  1. -m 自动创建用户主目录、并把框架目录(默认 /etc/skel)下的文件复制到用户主目录下。
  2. -g 创建用户时可以指定所创建的组名(已经存在的)
[root@localhost ~]# useradd-g xiaowang useradd-g
[root@localhost ~]# id useradd-g
uid=504(useradd-g) gid=503(xiaowang) 组=503(xiaowang)

[root@localhost ~]# useradd == -g xiaowang== useradd-g
3. -G可以指定其他的组名(意思是创建用户时自动加入到这些组里面来)

[root@localhost ~]# useradd -g xiaowang useradd-g-G -G xiaoming,xiaohua
[root@localhost ~]# id useradd-g-G
uid=505(useradd-g-G) gid=503(xiaowang) 组=503(xiaowang),501(xiaoming),502(xiaohua)

[root@localhost ~]# useradd -g xiaowang useradd-g-G -G xiaoming,xiaohua
4. -s指定用户的登录shell:

[root@localhost ~]# useradd -s /bin/sh useradd-s
[root@localhost ~]# cat /etc/passwd
useradd-g-G:x:505:503::/home/useradd-g-G:/bin/bash(默认)  
useradd-s:x:506:506::/home/useradd-s:/bin/sh(指定)
[root@localhost ~]# su - useradd-s
-sh-4.1$ 
-sh-4.1$ exit
logout

useradd-g-G: x:505:503::/home/useradd-g-G:/bin/bash(默认)
useradd-s: x:506:506::/home/useradd-s:/bin/sh(指定)

  1. -c 用于描述用户账号信息:
[root@localhost ~]# useradd -c "this is useradd-c" useradd-c
[root@localhost ~]# cat /etc/passwd
useradd-s:x:506:506::/home/useradd-s:/bin/sh   #默认为空
useradd-c:x:507:507:this is useradd-c:/home/useradd-c:/bin/bash

useradd-s: x:506:506==::==/home/useradd-s:/bin/sh #默认为空
useradd-c: x:507:507:this is useradd-c:/home/useradd-c:/bin/bash
6. -d 可以指定用户的家目录(目录不存在的):

[root@localhost ~]# useradd -d /useradd-d useradd-d
[root@localhost ~]# su - useradd-d
[useradd-d@localhost ~]$ cd /
[useradd-d@localhost /]$ ls
bin   etc   lib64       misc  opt           root     srv  ==useradd-d==  xiaoming-home
boot  home  lost+found  mnt   private-data  sbin     sys  usr        yuanyi
dev   lib   media       net   proc          selinux  tmp  var
[useradd-d@localhost /]$ cd useradd-d
[useradd-d@localhost ~]$ ls
[useradd-d@localhost ~]$ ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .gnome2  .mozilla
[useradd-d@localhost ~]$ cd ..
[useradd-d@localhost /]$ cd home
[useradd-d@localhost home]$ ls
useradd-c  useradd-g  useradd-g-G  useradd-s  xiaohua  xiaoming  xiaowang  yy  #把家目录存到指定地方去了,默认应该在这儿;

在这里插入图片描述

  1. 除了ROOT用户以外,每个用户都是以UID,GID500开始(操作系统只认UID GID来识别用户)
    [root@XYZ ~]# useradd -e 201711 ccie #-e设置用户的过期时间

[root@XYZ ~]# useradd -f 2 ccii #( -f, --inactive 帐号过期几天后停用)

2.9 useradd参数的综合应用

[root@localhost ~]# useradd -m -g root -G xiaohua,xiaowang -s /bin/shell -d /xxxx -u 999 -c "this is useradd-all"  useradd-all
[root@localhost ~]# id useradd-all
uid=999(useradd-all) gid=0(root) 组=0(root),502(xiaohua),503(xiaowang)
[root@localhost ~]# cat /etc/passwd
useradd-all:x:999:0:this is useradd-all:/xxxx:/bin/shell

该文件主要定义的是默认家目录、环境配置文件目录、登入执行的首个程序等等;

2.10 useradd 的配置文件介绍:

[root@localhost ~]# cat /etc/default/useradd 
# useradd defaults file   #useradd默认文件
GROUP=100          #表示可以创建普通组
HOME=/home			#用户的家目录建在/home中;用户家目录的默认创建地
INACTIVE=-1			#是否启用账号过期停权,-1表示不启用
EXPIRE=				#账号终止日期,不设置表示不启用;即无限期;账号
SHELL=/bin/bash		#所用SHELL类型;登录后执行的程序
SKEL=/etc/skel		#用户家目录中的环境文件,默认添加用户的目录默认文件存放位置;也就是说,当我们用useradd添加用户时,用户目录下的文件,都是从这个目录下复制过去的;
CREATE_MAIL_SPOOL=yes	#是否创建用户邮件缓存,yes表示创建

2.11 查看用户属性

[root@localhost ~]# chage -l useradd-all  #查看最近的变化
Last password change					: Aug 13, 2020
Password expires					: never
Password inactive					: never
Account expires						: never
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

2.12 id命令:查看用户信息

[root@localhost mail]# id root
uid=0(root) #当前用户的uid
gid=0(root) #当前用户的gid
组=0(root) #当前用户所在的组的信息

2.13 给用户指定密码:

  1. 更改系统用户密码:
[root@localhost mail]# cd /
[root@localhost /]# passwd rpc
更改用户 rpc 的密码 。
新的 密码:
[root@localhost /]# passwd xiaohua
更改用户 xiaohua 的密码 。
新的 密码:
无效的密码: 过于简单化/系统化
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
  1. 显示密码状态信息
[root@localhost /]# passwd -S xiaohua
xiaohua PS 2020-08-13 0 99999 7 -1 (密码已设置,使用 SHA512 加密。)
  1. 删除密码
[root@localhost /]# passwd -d xiaohua
清除用户的密码 xiaohua。
passwd: 操作成功
[root@localhost /]# passwd -S xiaohua
xiaohua NP 2020-08-13 0 99999 7 -1 (密码为空。)
  1. 设置密码立即过期(强制用户在下一次登录的时候更改密码)
[root@localhost /]# 
[root@localhost /]# passwd -e xiaohua 
Expiring password for user xiaohua.
passwd: 操作成功
[root@localhost /]# su - xiaohua 
[xiaohua@localhost ~]$ su - root
密码:
su: 密码不正确
[xiaohua@localhost ~]$ 
[xiaohua@localhost ~]$ su - xiaohua 
您需要立即更改密码(root 强制)
新的 密码:
无效的密码: 过于简单化/系统化
新的 密码:
无效的密码: 过于简单化/系统化
新的 密码:
重新输入新的 密码:

再次登录会让你重新设置一个密码,且密码不能太简单;
在这里插入图片描述

  1. 锁定系统用户密码(可以登录,但是用户不能修改自己的密码)
[xiaohua@localhost ~]$ su root
密码:
[root@localhost xiaohua]# passwd -l xiaohua
锁定用户 xiaohua 的密码 。
passwd: 操作成功
[root@localhost xiaohua]# passwd -u xiaohua
解锁用户 xiaohua 的密码 。
passwd: 操作成功

在这里插入图片描述

  1. 设置密码更改的最短时间:

[root@localhost ~]# passwd -n 90 test  #用户必须在90天内更改密码
[root@localhost ~]# passwd -i 20 test 	#密码过期后再过20天没有更改密码,用户将不能登录
[root@localhost ~]# passwd -w 10 test		#设置密码过期前的警告期限,提示10天后,他的密码将会过
[root@localhost ~]# passwd -x 100 test  #设置密码过期时间

在这里插入图片描述

testPS2020-08-13901001020
用户名密码设置
LK:密码锁定
NP:没有密码
创建时间-n:最短密码更改时间-x:密码过期时间-w:密码过期前警告-i:密码过期后还能使用的时间
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值