美文网首页
用户和组的管理

用户和组的管理

作者: 一秃脚丫子 | 来源:发表于2020-04-27 10:33 被阅读0次

一、linux 用户和组的主要配置文件##

1、/etc/passwd 用户及属性信息(名称、UID、主组ID等);
2、 /etc/group
...
[11:05:11 root@centos ~]#cat /etc/group
liu:x:1000:
...

二、shadow文件格式

群组名称-群组密码-组管理员密码-以当前组为附加组的用户列表

三、用户和组管理命令

1、用户管理命令
(1)创建用户 useradd
(2)修改用户 usermod
(3)删除用户 userdel
...

四、用户创建

常见选项
-d 指定家目录(实际不存在)
-m 创建家目录,用于系统用户;
-r 建立系统账号
-u 指定用户id
-g 指定用户所属群组
-s指定用户登入后所使用的shell。
-c加上备注文字
(重点)举例:给进程创建的常见用户
useradd -r -u 48 -g apache -s /sbin/nologin -d /var/www -c "Apache" apache
创建一个系统账号,UID为48,所属主组是阿帕奇,shell类型是nologin,家目录/var/www 描述为apache ,角色为apache
需要记住的有:
-r 创建系统账号
-u用户ID
-g所属组名
-s shell类型
-d 创建家目录
-c描述
举例: 创建nginx,并描述‘’
useradd -c "描述" 角色,
[17:19:06 root@centos ~]#useradd -c "nginx user" nginx
[17:27:53 root@centos ~]#cat /etc/passwd
...

五、修改用户

可修改用户的附加组,增加或者删除;
举例:添加附加组
...
[14:52:14 root@centos ~]#usermod -aG root liu
[14:52:26 root@centos ~]#id liu
uid=1000(liu) gid=1000(liu) groups=1000(liu),0(root)
...
举例:删除附加组
...
[15:27:38 root@centos ~]#usermod -G "" liu
[15:27:51 root@centos ~]#id liu
uid=1000(liu) gid=1000(liu) groups=1000(liu)
[15:27:56 root@centos ~]#
...

六、创建用户组

(重点)举例:创建组
...
groupadd -g 48 -r apache

-g 指定组编号
-r 创建系统组
...

七、临时切换主组

1、举例: newrp
...
[16:16:10 root@centos ~]#getent gshadow //账户的隐藏文件
root::: 判断无口令
bin:::
daemon:::
sys:::
adm:::

[16:14:08 root@centos ~]#su - liu //切换用户
[liu@centos ~]$

[liu@centos ~]$

[liu@centos ~]$ id
uid=1000(liu) gid=1000(liu) groups=1000(liu) //组为liu,需切换root context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

[liu@centos ~]$ newgrp root

Password:
newgrp: failed to crypt password with previous salt: Invalid argument
[liu@centos ~]$ getent gshadow

[liu@centos ~]$

[liu@centos ~]$ newgrp root
Password: //无口令密码。需创建

[liu@centos ~]$ id

uid=1000(liu) gid=0(root) groups=0(root),1000(liu)

context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
...

2、组密码:gpasswd
设置管理用户组
使用-a可以添加用户到组;
使用-d可以删除用户到组;
3、改变shell类型
chsh -s shell类型 用户

八、改变文件或目录用户和用户组

格式

...利用chown进行改变文件用户
[15:50:39 root@centos data]#chown liu 1.txt
[16:02:21 root@centos data]#ll
total 8
-rw-r--r--. 1 liu root 28 Apr 24 16:59 1.txt
-rw-r--r--. 1 root root 72 Apr 24 14:20 2.txt
-rw-r--r--. 1 root root 0 Apr 24 11:55 stdout.log
...
...利用chown加分号进进行改变文件用户组
[16:02:44 root@centos data]#chown :centos 1.txt
[16:11:51 root@centos data]#ll
total 8
-rw-r--r--. 1 liu centos 28 Apr 24 16:59 1.txt
-rw-r--r--. 1 root root 72 Apr 24 14:20 2.txt
-rw-r--r--. 1 root root 0 Apr 24 11:55 stdout.log
...
...利用chown改变文件的用户和用户组
[16:11:55 root@centos data]#chown root.bin 1.txt
[16:12:44 root@centos data]#ll
total 8
-rw-r--r--. 1 root bin 28 Apr 24 16:59 1.txt
-rw-r--r--. 1 root root 72 Apr 24 14:20 2.txt
-rw-r--r--. 1 root root 0 Apr 24 11:55 stdout.log
...
...chown利用分号改变用户和用户组
[16:56:34 root@centos data]#chown centos1:centos1 1.txt
[16:57:15 root@centos data]#ll
total 8
-rw-r--r--. 1 centos1 centos1 28 Apr 24 16:59 1.txt
-rw-r--r--. 1 root root 72 Apr 24 14:20 2.txt
-rw-r--r--. 1 root root 0 Apr 24 11:55 stdout.log
[16:57:16 root@centos data]#
...
...利用参考某一文件使另一文件的所属者和所属组与这一文件一致
[17:04:00 root@centos data]#chown --reference(参考)=1.txt 2.txt
[17:04:36 root@centos data]#ll
total 8
-rw-r--r--. 1 centos1 centos1 28 Apr 24 16:59 1.txt
-rw-r--r--. 1 centos1 centos1 72 Apr 24 14:20 2.txt
-rw-r--r--. 1 root root 0 Apr 24 11:55 stdout.log
[17:04:38 root@centos data]#
...
...chgrp只修改文件的所属组;
[17:27:05 root@centos data]#chgrp admins 1.txt
[17:28:47 root@centos data]#ll 1.txt
-rw-r--r--. 1 centos1 admins 28 Apr 24 16:59 1.txt
...

相关文章

  • Linux用户及用户组

    用户、组和权限管理 组 Linux用户和组管理

  • Linux-用户管理和用户组管理

    用户管理和用户组管理 一、用户管理 1.添加用户 2.切换用户 3.删除用户 二、用户组 三、用户管理与用户组管理...

  • Linux学习第五天

    用户账户的管理 一、用户账户和组账户概述 用户和用户组管理,顾名思义就是添加用户和用户组、更改密码和设定权限等操作...

  • Linux 2018-10-21

    用户管理和用户组管理 用户:使用操作系统的人用户组:具有相同系统权限的一组用户whoami ...

  • Linux运维之道(8)——用户和组管理

    @(Linux)[用户和组管理] 1. 用户和组管理 1.1 资源分派三元组 Authentication:认证 ...

  • Linux操作系统--用户和用户组(八)

    一、用户和用户组 用户和用户组管理,顾名思义就是添加用户和用户组、更改密码和设定权限等操作。 Linux用户和组的...

  • 大数据学习1-linux

    day1 用户和用户组管理 权限管理

  • 7.Metabase用户管理

    Metabase中只有系统管理员可以对用户管理,用户管理主要包括两个大的模块:用户组的管理和用户管理。其中用户组的...

  • Linux系统的用户和用户组管理

    Linux系统的用户和用户组管理

  • Linux第二天

    Linux第二天 用户和用户组管理 在Linux中通过配置文件来存储用户和用户组信息 用户管理 用户添加 : us...

网友评论

      本文标题:用户和组的管理

      本文链接:https://www.haomeiwen.com/subject/enlbihtx.html