CentOS7用户和组的创建及文件权限管理

CentOS7⽤户和组的创建及⽂件权限管理
⽤户与组的创建
概念和基本信息
centos Linux⽤户中分为三类⽤户:即超级⽤户(root⽤户、根⽤户,⽤户UID=0)、普通⽤户(⽤户UID>=1000)、伪⽤户(⽤户
UID=1~999)
氧浓度传感器centos Linux组分类也和⽤户类似,普通组GID>=1000。
超级⽤户拥有系统的最⾼权限,甚⾄可以删除系统;普通⽤户相对于超级⽤户少了很多权限,⽐如删除⽤户,禁⽌⽤户,添加⽤户组,删除⽤户组,修改系统配置等等;伪⽤户是⽆法使⽤密码登陆的,即仅仅⽤于系统⾃动的⽤户,⼈是⽆法⽤于登陆使⽤的
linux系统⽀持多⽤户,除了管理员,其他⽤户⼀般不应该使⽤root,⽽是应该向管理员申请⼀个账号。组类似于⾓⾊,系统可以通过组对有共性的⽤户进⾏统⼀管理。每个⽤户应该⾄少属于⼀个组,不能游离于组外;且在创建⽤户时,系统会在/home⽬录下⾃动⽣成⼀个⽬录作为该⽤户的“家⽬录”,该⽤户在
登录后会⾸先进⼊家⽬录。家⽬录可以在添加⽤户时指定,如果不指定,默认会以⽤户名来命名。例如,⽤户bob的家⽬录默认是/home/bob,他在登录linux系统后,会⾸先进⼊/home/bob。
⽤户与组基本信息
/etc/passwd是⽤来储存⽤户信息的⽂件,/etc/shadow是⽤来储存⽤户加密后密码及密码相关属性的⽂件, /etc/group是⽤来存放⽤户组信息的⽂件,/etc/gshadow加密后的组密码,⼀般不会使⽤。
每个⽤户应该⾄少属于⼀个初始组,但是可以属于多个附加组。⼀般情况下,⽤户的初始组就是在建⽴⽤户的同时建⽴的和⽤户名相同的组。⽤户的权限也只属于当前的初始组。
/etc/group
/etc/gshadow
组的创建
[root@usertest ~]# groupadd -h
Usage: groupadd [options] GROUP
Options:
-f, --force                  exit successfully if the group already exists,
and cancel -g if the GID is already used
-g, --gid GID                use GID for the new group
-h, --help                    display this help message and exit
-K, --key KEY=VALUE          override /etc/login.defs defaults
-o, --non-unique              allow to create groups with duplicate
(non-unique) GID
-p, --password PASSWORD      use this encrypted password for the new group
-r, --system                  create a system account
-
R, --root CHROOT_DIR        directory to chroot into
-P, --prefix PREFIX_DIR      directory prefix
-f, --force            如果组存在则成功退出,不创建新的组,如果组ID已经存在则取消-g 参数设置
-g, --gid GID              设置组ID,未指明则就会按照⽤户组ID中上⼀个gid⾃增1
-o, --non-unique              允许组ID(GID)不唯⼀,可重复。
-p, --password PASSWORD      设置组密码,⼀般不会使⽤
创建三个组 group1,group2,group3
groupadd group1
groupadd -g 2000 group2
groupadd group3
查看组信息可以看到三个新创建的组。
cat /etc/group
信息使⽤:分隔。分为4部分
组名:密码:组ID(GID):组中⽤户列表
hunt-079组名修改及组删除
修改组
[root@usertest ~]# groupmod -h
Usage: groupmod [options] GROUP
Options:
-g, --gid GID                change the group ID to GID
-h, --help                    display this help message and exit
-n, --new-name NEW_GROUP      change the name to NEW_GROUP
-o, --non-unique              allow to use a duplicate (non-unique) GID
-p, --password PASSWORD      change the password to this (encrypted)
PASSWORD
-R, --root CHROOT_DIR        directory to chroot into
-P, --prefix PREFIX_DIR      prefix directory where are located the /etc/* files
-g, --gid GID                修改组ID(GID)
-n, --new-name NEW_GROUP      修改组名
-o, --non-unique              允许设置的组ID重复
-p, --password PASSWORD      修改组密码
groupmod -g 1002 group2
groupmod -g 1111 -n group1111 group3
删除组
[root@usertest ~]# groupdel -h
Usage: groupdel [options] GROUP
Options:
-h, --help                    display this help message and exit
-R, --root CHROOT_DIR        directory to chroot into
-P, --prefix PREFIX_DIR      prefix directory where are located the /etc/* files  -f, --force                  delete group even if it is the primary group of a user
⽤户
/etc/passwd
/etc/shadow
⽤户的创建
[root@usertest ~]# useradd -h
Usage: useradd [options] LOGIN
useradd -D
useradd -D [options]
Options:
-b, --base-dir BASE_DIR      base directory for the home directory of the
new account
-c, --comment COMMENT        GECOS field of the new account
微冻技术-d, --home-dir HOME_DIR      home directory of the new account
-D, --defaults                print or change default useradd configuration
-
e, --expiredate EXPIRE_DATE  expiration date of the new account
-f, --inactive INACTIVE      password inactivity period of the new account
-g, --gid GROUP              name or ID of the primary group of the new
account
-G, --groups GROUPS          list of supplementary groups of the new
account
-h, --help                    display this help message and exit
-k, --skel SKEL_DIR          use this alternative skeleton directory
-K, --key KEY=VALUE          override /etc/login.defs defaults
-l, --no-log-init            do not add the user to the lastlog and
faillog databases
-
m, --create-home            create the user's home directory
-M, --no-create-home          do not create the user's home directory
-N, --no-user-group          do not create a group with the same name as
the user
巴氏杀菌锅-o, --non-unique              allow to create users with duplicate
(non-unique) UID
-p, --password PASSWORD      encrypted password of the new account
-r, --system                  create a system account
-R, --root CHROOT_DIR        directory to chroot into
-P, --prefix PREFIX_DIR      prefix directory where are located the /etc/* files
-s, --shell SHELL            login shell of the new account
-
udnu, --uid UID                user ID of the new account
-U, --user-group              create a group with the same name as the user
-Z, --selinux-user SEUSER    use a specific SEUSER for the SELinux user mapping
常⽤
Options:
-b, --base-dir BASE_DIR      设置⽤户家⽬录的⽗⽬录
-d, --home-dir HOME_DIR      设置⽤户的家⽬录
-g, --gid GROUP              设置⽤户的组id或组名
-G, --groups GROUPS          设置⽤户的附加ID
-m, --create-home            创建⽤户时创建⽤户家⽬录
-M, --no-create-home          创建⽤户时不创建⽤户家⽬录
-
o, --non-unique              允许⽤户的uid重复
-p, --password PASSWORD      设置⽤户的登录密码,⼀般不会在创建时指定。
-s, --shell SHELL            设置⽤户所⽤的shell
-u, --uid UID                ⽤户的uid
-U, --user-group              创建⽤户时创建组,组名和⽤户名相同
默认情况,⽤户家⽬录的⽗⽬录是 /home ⽤户的家⽬录和⽤户名⼀致,组名和⽤户名⼀致,创建⽤户时创建家⽬录,不允许⽤户uid重复,⽆密码。
⽤户创建
useradd user1
groupadd group2
ppzhus
useradd -g group2 user2
useradd -d /user3 -p 123456 user3
为⽤户设置密码
passwd user1
查看⽤户信息
cat /etc/passwd
主要看最后三⾏,⽤户信息⽤ : 分隔。分别是
⽤户名 : ⽤户密码(使⽤X代替,具体存储在/etc/shadow) : ⽤户ID : 组ID : ⽤户注释信息 : ⽤户的家⽬录 : ⽤户登录所使⽤的shell
user3 的 家⽬录 是 /user3,⽽未设置家⽬录的user1 user2 家⽬录是/home 下的同名⽂件夹。
查看⽤户密码
cat /etc/shadow
看最后三⾏,user1 user2 user3
user2未设置密码,user1和user3密码都为123456 但是user1是创建后设置的密码,因此是加密的,user3是创建时设置的密码,不是加密的。(奇怪的是user3密码好像⽆法使⽤。。。) 因此⽤户密码设置最好是创建⽤户之后使⽤passwd 命令设置⽽不是直接使⽤-p 参数设置
查看⽤户信息
id ⽤户名
id user1
id user2
id user3

本文发布于:2024-09-21 13:48:17,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/243256.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:密码   创建   设置   信息   户组   属于   删除   组名
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议