当前位置:   article > 正文

linux 添加用户到组命令,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 ~]#

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/621018
推荐阅读
相关标签
  

闽ICP备14008679号