linux 添加用户到组命令,linux下添加用户组和用户

1,linux下文件权限管理,添加用户组并添加用户

添加组:groupadd 组名

groupadd deploy

cat /etc/group | grep deploy

如图:

删除组:groupdel 组名

groupdel deploy

cat /etc/group | grep deploy

查询组:cat /etc/group 或者使用管道来精确查询 cat /etc/group | grep dev

如图:

/etc 目录是专门用来保存 系统配置信息 的目录

group 是保存组信息的文件

2,添加用户

添加用户:useradd -m -g 组 新建用户名 注意:-m 自动建立用户家目录; -g 指定用户所在的组,否则会建立一个和用户名同名的组

useradd -m -g deploy test

deploy 为用户组,test1为用户名

查询用户:在/etc/passwd文件下存储的是用户的list

cat /etc/passwd

如图:

只查找deploy用户

id deploy

如图:

修改和创建密码 passwd 用户名 如果不加用户名则默认修改当前登录者的密码

[root@Server-n93yom ~]# passwd test1

Changing password for user test1.

New password:

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:

passwd: all authentication tokens updated successfully.

[root@Server-n93yom ~]#

设置好密码后,使用此账号和密码登录

➜ ~ ssh test1@192.168.85.163

test1@192.168.85.163's password:

Last failed login: Mon Jul 22 17:00:05 CST 2019 from 192.168.1.53 on ssh:notty

There were 3 failed login attempts since the last successful login.

[test1@Server-n93yom ~]$

设置用户不能修改密码

[root@Server-n93yom ~]# passwd -l test1 //在root下,禁止test1用户修改密码的权限

Locking password for user test1. //锁住test1不能修改密码

passwd: Success

[root@Server-n93yom ~]# su test1 //切换用户

[test1@Server-n93yom root]$ passwd //修改密码

Changing password for user test1.

Changing password for test1.

(current) UNIX password:

passwd: Authentication token manipulation error //没用权限修改密码

[test1@Server-n93yom root]$

清除密码

[root@Server-n93yom ~]# passwd -d test1 //删除test1的密码

Removing password for user test1.

passwd: Success

[root@Server-n93yom ~]# passwd -S test1 //查看test1的密码

test1 NP 2019-07-22 0 99999 7 -1 (Empty password.) //密码为空

[root@Server-n93yom ~]#

passwd 帮助命令

[root@Server-n93yom ~]# passwd --help

Usage: passwd [OPTION...]

-k, --keep-tokens keep non-expired authentication tokens

-d, --delete delete the password for the named account (root only)

-l, --lock lock the password for the named account (root only)

-u, --unlock unlock the password for the named account (root only)

-e, --expire expire the password for the named account (root only)

-f, --force force operation

-x, --maximum=DAYS maximum password lifetime (root only)

-n, --minimum=DAYS minimum password lifetime (root only)

-w, --warning=DAYS number of days warning users receives before password

expiration (root only)

-i, --inactive=DAYS number of days after password expiration when an account

becomes disabled (root only)

-S, --status report password status on the named account (root only)

--stdin read new tokens from stdin (root only)

Help options:

-?, --help Show this help message

--usage Display brief usage message

[root@Server-n93yom ~]#

  • 5
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值