Linux增删用户

Linux增删用户

1.添加用户

//添加一个test用户
[root@localhost ~]# adduser test
//设置test用户密码
[root@localhost ~]# passwd test
Changing password for user test.
//在这里设置密码
New password: 
BAD PASSWORD: The password is shorter than 8 characters
//再次输入上面的密码
Retype new password: 
passwd: all authentication tokens updated successfully.
//[root@localhost ~]代表是root账户   在root账户切换到普通账户,这里不需要密码
[root@localhost ~]# su test
//[test@localhost root]代表test账户  在test账户切换到root账户,这里需要root账户的密码
[test@localhost root]$ su root
Password: 
//为了测试上面test账户密码是有效的,在这里再创建一个test1
[root@localhost ~]# adduser test1
//切换到test1
[root@localhost ~]# su test1
//[test1@localhost root] 这里已经是test1了,然后切换到test
[test1@localhost root]$ su test
Password: 
//上面输入test密码成功进到test账户,证明密码是有效的
[test@localhost root]$ 
[test@localhost root]$ 
//用test去创建账号,会提示你权限不够
[test@localhost /]$ adduser test2
bash: /usr/sbin/adduser: Permission denied
[test@localhost /]$ 



对上面进行总结:因为linux是多用户系统,root具有最高权限,所以可以随意建用户,其它普通用户不能创建用户

其实上面就用到三条命名

adduser 你要建的用户名
passwd  这里输入你要建的用户名,为其设置密码
su 你建的用户名,进行用户之间的切换

2.删除账号

//test用户删test1用户会提示权限不够
[test@localhost /]$ userdel test1
bash: /usr/sbin/userdel: Permission denied
[test1@localhost /]$ su root
Password: 
//删除test1
[root@localhost /]# userdel test1
userdel: user test1 is currently used by process 25555
//上面报错了,直接退出
[root@master ~]# exit
[test1@master root]$ exit
//再执行删除
[root@master ~]# userdel test1
//再切换时会报不存在,代表删除成功
[root@master ~]# su test1
su: user test1 does not exist
[root@master ~]# 


对上面进行总结:普通用户是不能删除普通用户的,只有root可以删

用到命令

userdel  你要删除的用户名
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值