Linux Admin教程

Linux Admin 用户

在讨论 用户管理时,我们需要理解三个重要的术语-
Users Groups Permissions
我们已经ady 深入讨论了应用于文件和文件夹的权限。在本章中,让我们讨论用户和组。

CentOS 用户

在 CentOS 中,有两种类型的帐户-
System accounts-用于守护程序或其他软件。 Interactive accounts-通常分配给访问系统资源的用户。
两种用户类型之间的主要区别是-
System accounts被守护进程用来访问文件和目录。这些通常不允许通过 shell 或物理控制台登录进行交互式登录。 Interactive accounts被最终用户用来通过 shell 或物理控制台登录访问计算资源。
有了对用户的基本了解,现在让我们为会计部门的 Bob Jones 创建一个新用户。使用 adduser 命令添加新用户。
以下是一些 adduser 常用Switch-
Switch Action
-c 向用户帐户添加评论
-m 在默认位置创建用户主目录,如果不存在
-g 分配给用户的默认组
-n 不为用户创建私有组,通常是用户名的组
-M 不创建主目录
-s 除/bin/bash 之外的默认 shell
-u 指定UID(否则由系统分配)
-G 要分配给用户的其他组
创建新用户时,使用 -c,-m,-g,-n Switch如下-
[root@localhost Downloads]# useradd-c "Bob Jones Accounting Dept Manager" 
-m-g accounting-n bjones
现在让我们看看我们的新用户是否已经创建-
[root@localhost Downloads]# id bjones 
(bjones) gid = 1001(accounting) groups = 1001(accounting)
[root@localhost Downloads]# grep bjones /etc/passwd 
bjones:x:1001:1001:Bob Jones  Accounting Dept Manager:/home/bjones:/bin/bash
[root@localhost Downloads]#
现在我们需要使用 passwd 命令启用新帐户-
[root@localhost Downloads]# passwd bjones 
Changing password for user bjones. 
New password:  
Retype new password:  
passwd: all authentication tokens updated successfully.
[root@localhost Downloads]#
未启用用户帐户,允许用户登录系统。

禁用用户帐户

有多种方法可以禁用系统上的帐户。这些范围包括手动编辑/etc/passwd 文件。或者甚至使用带有 -l Switch的 passwd 命令。这两种方法都有一个很大的缺点:如果用户具有 ssh 访问权限并使用 RSA 密钥进行身份验证,他们仍然可以使用这种方法登录。
现在让我们使用 chage 命令,将密码到期日期更改为以前的日期。此外,最好在帐户上注明我们禁用它的原因。
[root@localhost Downloads]# chage-E 2005-10-01 bjones
 
[root@localhost Downloads]# usermod -c "Disabled Account while Bob out of the country 
for five months" bjones
[root@localhost Downloads]# grep bjones /etc/passwd 
bjones:x:1001:1001:Disabled Account while Bob out of the country for four 
months:/home/bjones:/bin/bash
[root@localhost Downloads]#

管理群组

在 Linux 中管理组使管理员可以方便地将容器内的用户组合在一起,并应用适用于所有组成员的权限集。例如,Accounting 中的所有用户可能需要访问相同的文件。因此,我们创建了一个会计组,添加了会计用户。
在大多数情况下,任何需要特殊权限的事情都应该在一个组中完成。与仅对一个用户应用特殊权限相比,这种方法通常会节省时间。例如,Sally 负责报告,只有 Sally 需要访问某些文件才能进行报告。但是,如果有一天 Sally 生病了而 Bob 报告了呢?或者报告的需求在增长?创建组后,管理员只需执行一次。添加用户会随着需求的变化或扩展而应用。
以下是用于管理组的一些常用命令-
chgrp groupadd 用户模式
chgrp-更改文件或目录的组所有权。
让我们为会计组的人创建一个目录来存储文件并为文件创建目录。
[root@localhost Downloads]# mkdir /home/accounting
[root@localhost Downloads]# ls-ld /home/accounting
drwxr-xr-x. 2 root root 6 Jan 13 10:18 /home/accounting
[root@localhost Downloads]#
接下来,让我们将 组所有权授予 会计 组。
[root@localhost Downloads]# chgrp-v  accounting /home/accounting/ 
changed group of ‘/home/accounting/’ from root to accounting
[root@localhost Downloads]# ls-ld /home/accounting/ 
drwxr-xr-x. 2 root accounting 6 Jan 13 10:18 /home/accounting/
[root@localhost Downloads]#
现在,accounting 组中的每个人都拥有 /home/accounting读取执行 权限。他们也需要写权限。
[root@localhost Downloads]# chmod g+w /home/accounting/
[root@localhost Downloads]# ls-ld /home/accounting/ 
drwxrwxr-x. 2 root accounting 6 Jan 13 10:18 /home/accounting/
[root@localhost Downloads]#
由于 会计组可能处理敏感文档,我们需要为 otherworld申请一些限制性的权限。
[root@localhost Downloads]# chmod o-rx /home/accounting/
[root@localhost Downloads]# ls-ld /home/accounting/ 
drwxrwx---. 2 root accounting 6 Jan 13 10:18 /home/accounting/
[root@localhost Downloads]#
groupadd-用于创建一个新组。
Switch Action
-g 指定组的 GID
-K 覆盖/etc/login.defs 中 GID 的规范
-o 允许覆盖非唯一组 ID 不允许
-p 群组密码,允许用户自行激活
让我们创建一个名为 secret 的新组。我们将为群组添加密码,允许用户使用已知密码添加自己。
[root@localhost]# groupadd secret
[root@localhost]# gpasswd secret 
Changing the password for group secret 
New Password:  
Re-enter new password:
[root@localhost]# exit 
exit
[centos@localhost ~]$ newgrp secret 
Password:
[centos@localhost ~]$ groups 
secret wheel rdc
[centos@localhost ~]$
实际上,组的密码并不经常使用。辅助组就足够了,在其他用户之间共享密码并不是一个很好的安全做法。
groups 命令用于显示用户属于哪个组。我们将在对当前用户进行一些更改后使用它。
usermod 用于更新帐户属性。
以下是常见的 usermod Switch。
Switch Action
-a 附加,将用户添加到补充组,仅使用-G 选项
-c Comment,更新用户评论值
-d 主目录,更新用户的主目录
-G 分组、添加或删除次要用户组
-g Group,用户的默认主组
[root@localhost]# groups centos 
centos : accounting secret
[root@localhost]#
[root@localhost]# usermod-a-G wheel centos
[root@localhost]# groups centos
centos : accounting wheel secret
[root@localhost]#
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4