linux测试有效组,软件测试:三分钟掌握Linux命令之用户&用户组命令(必读系列三)...

d1fb36900d1448cedfdac0e9b9d6cfb1.png

linux命令

目录1.文件和目录操作命令

2.用户和用户组操作命令

3.vim编辑器操作命令

4.打包和解压操作命令

5.系统操作命令

这是总的目录的,软件测试人员需要掌握的Linux命令会分成多个章节来写。

useradd 创建用户不指定任何信息,创建一个用户

格式:useradd 用户名[root@localhost network-scripts]# useradd test_dir

创建用户过程中,自动修改的文件有:

(1)passwd文件test_dir:x:502:502::/home/test_dir:/bin/bash

(2)shadow文件test_dir:!!:17270:0:99999:7:::

!!表示没有密码

17270为1970年1月1日到今天的天数,也就是时间戳

0表示两次密码修改间隔天数

99999表示密码的有效期,99999表示永久生效

7表示密码到期前的警告天数

密码到期后宽限天数(这里没有设置,为空,在二个冒号之间)

(3)group文件-在创建test_dir这个用户的同时,也创建一个与test_dir相同名称的组

test_dir:x:502:---组

(4)gshadow文件-指test_dir组的密码test_dir:!::

(5)家目录-新增一个test_dir的目录[root@localhost home]# ll

drwx------. 2 test_dir test_dir 4096 Apr 14 22:08 test_dir

(6)邮件-新一个test_dir的目录[root@localhost network-scripts]# ls -l /var/spool/mail/|grep test_dir

-rw-rw----. 1 test_dir mail 0 Apr 14 22:08 test_dir

2.添加参数增加用户

格式:useradd -u UID -d 家目录 -c 用户说明 -g 用户组 -G 附加组 用户名[root@localhost network-scripts]# useradd -u 555 -d /home/hom -c "tester" -g test -G wq test1

已经指定一个存在的初始组,那么就不会再增加与用户名相同的组test1:$6$mjPKHzI/$dg6TtCABUBmzKIwv8Xrvv1iAQVtRhkN0CIoFIqu.8CdyA.E6Rds.s.FcowhXNQAf/rf.znrgVayd8vLfhsBIt0:17270:0:99999:7:::

有密码时,!!会变成被加密后的字符串

用户没有密码时,不能登录

passwd 修改用户密码

1.root用户去修改密码,可以设置简单的密码

格式 :passwd 用户名[root@localhost network-scripts]# passwd test03

Changing password for user test03.

New password:

BAD PASSWORD: it is too simplistic/systematic

BAD PASSWORD: is too simple

Retype new password:

passwd: all authentication tokens updated successfully.

只有root才有权限去修改其它用户的密码,并且可以设置相对简单的密码

其他用户只能修改自己的密码,并且要根据linux密码设置规范去设置密码

2.test用户修改密码

格式:passwd[test@localhost ~]$ passwd

Changing password for user test.

Changing password for test.

(current) UNIX password:

New password:

BAD PASSWORD: it is too simplistic/systematic

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

不能少8个字符,且相对复杂的密码

3.passwd -S 显示用户的密码状态[root@localhost network-scripts]# passwd -S test

test PS 2017-04-14 0 99999 7 -1 (Password set, SHA512 crypt.)

4.passwd -l暂时锁定用户[root@localhost network-scripts]# passwd -l test

Locking password for user test.

passwd: Success

[root@localhost network-scripts]# cat /etc/shadow|grep test

test:!!$6$XQLbiOl1$b/OUZT0T21cZxnnLZrjBSIG1/IvyzvfFlqkERgTypWrdf5xJwmprm5.kntSiqJ2v9ozEVsPCI6OEfmPrQrBRa1:17270:0:99999:7:::

锁定用户其实就是在用户的密码标志前加上!!,将密码致为失效,相当于用户没有密码,没有密码的用户是不能进行登录的

5.passwd -u 解锁用户[root@localhost network-scripts]# passwd -u test

Unlocking password for user test.

passwd: Success

[root@localhost network-scripts]# cat /etc/shadow|grep test

test:$6$XQLbiOl1$b/OUZT0T21cZxnnLZrjBSIG1/IvyzvfFlqkERgTypWrdf5xJwmprm5.kntSiqJ2v9ozEVsPCI6OEfmPrQrBRa1:17270:0:99999:7:::

解锁用户就是去掉用户密码标志前的!!

3-5 中的命令只有root用户才有权限操作

usermod 修改用户的信息

1.修改test的UID为999 -u 手工指定的UID[root@localhost network-scripts]# usermod -u 999 test

2.修改test用户的用户说明为“tester lead” -c[root@localhost network-scripts]# usermod -c "tester lead" test

3.修改test用户的附加组为wq -G[root@localhost network-scripts]# usermod -G wq test

表示wq这个组的附加用户有test1用户,test用户

一个用户的初始组只有一个,可以拥有多个附加组

chage 修改用户的密码状态

-l ---显示密码的详细列表

-m ---修改二次密码间隔天数

-M ---修改密码的有效期

-W ---修改密码的警告天数

-I ---修改密码的宽限天数

-E ---修改账户失效日期

userdel 删除用户删除用户

格式:userdel 用户名

执行userdel 用户名时,文件的内容被修改的就是以下几个文件(etc)[root@localhost ~]# find /etc -mmin -2

而家目录下面,相同用户名的目录没有被删除

2.完全删除

格式:userdel -r 用户名[root@localhost home]# userdel -r test01

使用这个选项-r,不仅将etc下面的四个文件内容被修改了,而且还将home和mail目录下面,与用户名相同的目录被删除了

根据以上的信息,我们可以知道不管增加还是删除用户,修改的文件就是passwd shadow group gshadow ,还包含的home和mail目录

从而得知,如果是手工添加用户或删除用户,直接去修改这几个文件也可以达到相同的效果

id 显示用户的组ID和用户ID

格式:id 用户名[root@localhost mail]# id test

uid=999(test) gid=501(test) groups=501(test),500(wq)

不仅显示了用户ID,还显示了初始组ID,同时组中还包含了附加组的ID[root@localhost mail]# cat /etc/group |grep test

wq:x:500:test1,test

test:x:501:

su 切换用户

1.使用su命令时,一定要记得加上 - 代表同时切换环境变量(经常用)[root@localhost mail]# su - test

使用su命令时,不加 - 不能完全切换,这种用法是错误的(完全切换指的是环境变量跟着一起切换)

王豆豆在使用这个命令时吃过亏,从普通用户切换到root用户,给用户授权时,怎么使用命令都不对,检查了又检查,命令是对的啊,后来差点都怀疑人生了,最终才发现是切换用户时没有切换环境变量,导致显示的是root用户,实际上还是上一个普通用户的环境变量。

2.在不切换用户的时候,可以跟上 -c 使用其用户执行一次的命令[test@localhost home]$ su root -c "useradd test02"

Password:

groupadd 添加组添加组

格式:groupadd 组名

添加一个组时,修改的文件为group gshadow

2.-g 手工指定组ID

格式:groupadd -g GID 组名[root@localhost mail]# groupadd -g 1222 t2

groupadd所增加不是任何一个用户的初始组或者附加组

groupmod 修改组信息

1.修改组ID -g

格式:groupmod -g 新的组ID 组名[root@localhost mail]# groupmod -g 1112 t1

2.修改组的组名

格式:groupmod -n 新组名 旧组名

要把组名为t1的组改成组名为tt1[root@localhost mail]# groupmod -n tt1 t1

groupdel 删除组

1.删除的组既不是初始组也不是附加组[root@localhost mail]# groupdel t2

删除时修改的文件为group gshadow

2.删除初始组[root@localhost mail]# groupdel test

groupdel: cannot remove the primary group of user 'test'

用户的初始组不可以删除

如果要删除,解除绑定,将组改成非初始组

3.删除附加组[root@localhost mail]# cat /etc/group |grep test04

tt1:x:1112:test04

test04:x:1002:

[root@localhost mail]# groupdel tt1

[root@localhost mail]# cat /etc/group |grep test04

test04:x:1002:

如果一个组是某用户的附加组,可以被删除

从而得出初始组不能被删除,附加组可以被删除

gpasswd 给组添加附加用户或给组删除附加用户

gpasswd操作都是附加组

1.将test用户作为test03组的附加用户

格式:gpasswd -a 用户名 组名[root@localhost mail]# gpasswd -a test test03

Adding user test to group test03

test03:x:1000:test

表示test用户为test03的附加用户

2.删除test03组的附加用户test

格式:gpasswd -d 附加用户名 组名[root@localhost mail]# gpasswd -d test test03

Removing user test from group test03

[root@localhost mail]# cat /etc/group|grep test03

test03:x:1000:

以上命令是用户及用户组命令。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值