linux 系统组,linux系统怎么用
本篇文章给大家谈谈linux 系统组,以及linux系统怎么用对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了收藏本站喔。
linux系统组成部分linux系统组
如何在linux上用命令实现用户和组的管理?
Linux上用命令实现本地用户和组的管理
本地用户和组:管理文件和进程等等
本地用户和组:
1)root:超级管理员系统创建的第一个账户
特点:
id为:0
家目录:/root
具有系统的完全控制权:小心使用。
#id
uid=0(root)gid=0(root)groups=0(root)context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
#
2)普通用户:不具有管理员权限
特点:
id范围:
1000=id=60000
家目录:/home/用户名
#idstudent
uid=1000(student)gid=1000(student)groups=1000(student),10(wheel)
#
3)服务用户:为服务提供权限
特点:
id范围:
0id1000
家目录:应用程序服务目录
#idapache
uid=48(apache)gid=48(apache)groups=48(apache)
#
如果是yum,rpm安装的软件:由rpm包中的脚本创建服务账户
Includeconf.modules.d/*.conf
#
#Ifyouwishhttpdtorunasadifferentuserorgroup,youmustrun
#httpdasrootinitiallyanditwillswitch.
#
#User/Group:Thename(or#number)oftheuser/grouptorunhttpdas.
#Itisusuallygoodpracticetocreateadedicateduserandgroupfor
#runninghttpd,aswithmostsystemservices.
#
Userapache
Groupapache
#'Main'serverconfiguration
#
本地组:
1)主组:一个用户一定要属于某个主组中。当些用户在创建文件时,给文件的归属组
2)从属组:用户容器,组织和管理用户权限管控
作用:
文件:
进程:
$ps-ux
USERPID%CPU%MEMVSZRSSTTYSTATSTARTTIMECOMMAND
student321780.00.4930529360?Ss15:000:00/usr/lib/system
student321820.00.32537767072?S15:000:00(sd-pam)
student321880.00.21594124980?S15:000:00sshd:student@p
student321890.00.22339124864pts/0Ss15:000:00-bash
student322930.30.21594085192?D15:430:00sshd:student@p
student322940.30.22339124924pts/1Ss15:430:00-bash
student323190.50.22339404804pts/1S15:430:00/bin/bash
student323410.00.22693123876pts/1R+15:430:00ps-ux
$
账户文件:
1)/etc/passwd:保存用户信息
#cat/etc/passwd|grepstudent
student:x:1000:1000:StudentUser:/home/student:/bin/bash
用户名密码uid主组ID描述家目录登录shell
#
#cat/etc/passwd|grep-wroot:x
root:x:0:0:root:/root:/bin/bash
#
#cat/etc/passwd|grepapache
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
服务账号无法登录系统
#
2./etc/shadow:保存用户密码的HASH,密码的有效性信息,密码修改时间,账户有效期。
#
#ls-l/etc/shadow
----------.1rootroot1014Mar2911:39/etc/shadow
#
#
#cat/etc/shadow|grepstudent
student:$6$8oIjLCsc$/n1iQXYh1E6.uOEuJKgioqAtmqm2TQmkJGF2RwyteIr1tIfrPdiRYgWe6Sjen5/eMij2uHM/a1tue/QRlo3X80:18038:0:99999:7:::
#
密码的HASH:sha512
8oIjLCsc$/n1iQXYh1E6.uOEuJKgioqAtmqm2TQmkJGF2RwyteIr1tIfrPdiRYgWe6Sjen5/eMij2uHM/a1tue/QRlo3X80
18038:天数密码最后一次修改的时间从1970-01-01+18038天之后那一天
0:密码最少使用天数0没有限制用户随时可以改密码
99999:天数,密码最大修改时间永久200多年
7:warning警告时间,当密码快到最后修改时间前7天,通知用户修改。
::天数失效时间inactive用户密码过了最后修改时间,未改变密码,再过多少天,账户将被锁定
::账户有效期
创建用户和组:
创建时,没有密码:
#useraddzhangsan
#useraddlisi
#idzhangsan
uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan)
#idlisi
uid=1002(lisi)gid=1002(lisi)groups=1002(lisi)
#
无法登录:与PAM有关
$
$su-zhangsan
Password:
Password:
su:Authenticationfailure
$
设置密码:
#
#cat/etc/passwd|grepzhangsan
zhangsan:x:1001:1001::/home/zhangsan:/bin/bash
#cat/etc/shadow|grepzhangsan
zhangsan:!!:18350:0:99999:7:::#!!未设置密码
#
#passwdzhangsan
Changingpasswordforuserzhangsan.
Newpassword:
BADPASSWORD:Thepasswordisshorterthan8characters
Retypenewpassword:
passwd:allauthenticationtokensupdatedsuccessfully.
#
#
#cat/etc/shadow|grepzhangsan
zhangsan:$6$3wxuXomVbQ58wQcK$oQW6injgldxa2N/Pt4tCPDVRqWRVGw.UNZdxE4R0nhEt8K/3UDKzxap6ReIReEvDpG.GdwjpMiiDh7.f6DJNQ0:18350:0:99999:7:::
#
chage可以查看用户密码属性
#chage-lzhangsan
Lastpasswordchange:Mar29,2020
Passwordexpires:never
Passwordinactive:never
Accountexpires:never
Minimumnumberofdaysbetweenpasswordchange:0
Maximumnumberofdaysbetweenpasswordchange:99999
Numberofdaysofwarningbeforepasswordexpires:7
#
创建组:从属组
#
#groupaddit
#
#
#groupaddsales
#
#
#
#cat/etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:student
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:33:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
users:x:100:
nobody:x:65534:
dbus:x:81:
utmp:x:22:
utempter:x:35:
input:x:999:
kvm:x:36:
render:x:998:
systemd-journal:x:190:
systemd-coredump:x:997:
systemd-resolve:x:193:
tss:x:59:
polkitd:x:996:
rpc:x:32:
unbound:x:995:
ssh_keys:x:994:
sssd:x:993:
setroubleshoot:x:992:
rpcuser:x:29:
insights:x:991:
cockpit-ws:x:990:
sshd:x:74:
chrony:x:989:
tcpdump:x:72:
student:x:1000:
printadmin:x:988:
libstoragemgmt:x:987:
slocate:x:21:
postdrop:x:90:
postfix:x:89:
apache:x:48:
zhangsan:x:1001:
lisi:x:1002:
it:x:1003:组成员列表
sales:x:1004:
#
#idstudent
uid=1000(student)gid=1000(student)groups=1000(student),10(wheel)
#
将用户添加进组:zhangsan,加入it组,lisi,sales组
#idstudent
uid=1000(student)gid=1000(student)groups=1000(student),10(wheel)
#usermod-aGitzhangsan
#
#
#usermod-aGsaleslisi
#
#
#idzhangsan
uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan),1003(it)
#idlisi
uid=1002(lisi)gid=1002(lisi)groups=1002(lisi),1004(sales)
#
删除用户:
#useraddandy
默认删除,保留用户的文件:
#
#userdelandy
#
#
#useraddandy#重建andy会不一样,uid会不同
useradd:warning:thehomedirectoryalreadyexists.
Notcopyinganyfilefromskeldirectoryintoit.
Creatingmailboxfile:Fileexists
#
#useradduser1
#useradduser2
#idandy
uid=1003(andy)gid=1005(andy)groups=1005(andy)
#userdel-rany
userdel:user'any'doesnotexist
#
#userdel-randy#不保留用户的文件。家目,邮箱文件,skel文件都会
#
#
#idandy
id:‘andy’:nosuchuser
#useraddandy
#idandy
uid=1006(andy)gid=1008(andy)groups=1008(andy)
#
从组中移除用户:
#
#idzhangsan
uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan),1003(it)#zhangsan主组,it从属组
#
命令:
#gpasswd-dzhangsanit
Removinguserzhangsanfromgroupit
#
#
#idzhangsan
uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan)
#
#
#usermod-aGitzhangsan
#
#
#idzhangsan
uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan),1003(it)
#
#
#
#groupszhangsan
zhangsan:zhangsanit
#
直接修改文件:
#vim/etc/group
#cat/etc/group|grepit:
it:x:1003:
#
删除组:
#groupaddtest
#
#
#groupdeltest
创建自定义用户和组:
实验:用户名mary,指定用户id2000,家目录/maryhome,不用登录系统描述thisismaryuser
#
#useradd-u2000-d/maryhome-s/sbin/nologin-c"thisismary"mary
#
#idmary
uid=2000(mary)gid=2000(mary)groups=2000(mary)
#cat/etc/passwd|grepmary
mary:x:2000:2000:thisismary:/maryhome:/sbin/nologin
#
#su-mary
Lastlogin:SunMar2916:48:49CST2020onpts/0
Thisaccountiscurrentlynotavailable.
#
创建自定义组:指定组id
#groupadd-g3000group1
#cat/etc/group|grepgroup1
group1:x:3000:
#
linux属主和属组的区别?
区别如下:
linux的一切都是文件。Linux系统按文件所有者、文件所有者同组用户和其他用户来规定了不同的文件访问权限。
属主是某个文件的拥有者,属组是某个文件拥有者所在的组,对于文件来说,它都有一个特定的所有者,也就是对该文件具有所有权的用户。同时,在Linux系统中,用户是按组分类的,一个用户属于一个或多个组。文件所有者以外的用户又可以分为文件所有者的同组用户和其他用户。
linux系统组与用户组的区别?
Linux是多用户多任务操作系统,换句话说,Linux系统支持多个用户在同一时间内登录,不同用户可以执行不同的任务,并且互不影响。不同用户具有不问的权限,每个用户在权限允许的范围内完成不见的任务,Linux正是通过这种权限的划分与管理,实现了多用户多任务的运行机制。每个用户都有唯一的用户名和密码。在登录系统时,只有正确输入用户名和密码,才能进入系统和自己的主目录。用户组是具有相同特征用户的逻辑集合。简单的理解,有时我们需要让多个用户具有相同的权限,所有用户就具有了和组一样的权限,这就是用户组。将用户分组是Linux系统中对用户进行管理及控制访问权限的一种手段,通过定义用户组,很多程序上简化了对用户的管理工作。Linux用户和组的关系用户和用户组的对应关系有以下4种:一对一:一个用户可以存在一个组中,是组中的唯一成员;一对多:一个用户可以存在多个用户组中,此用户具有这多个组的共同权限;多对一:多个用户可以存在一个组中,这些用户具有和组相同的权限;多对多:多个用户可以存在多个组中,也就是以上3种关系的扩展。
在centoslinux中,命令的组成有?
、常用缩写习惯
cd==changedieectory##更改当前工作目录
dd==diskdump##磁盘转存
df==diskfree##磁盘自由
du==diskusage##磁盘详情
pwd==printworkingdirectory##打印当前工作目录
ps==processesstatus##工程状态
ps==promptstrings##提示字符串
su==substituteuser##切换用户
rc==runcommand##运行命令
tcl==toolcommandlanguage##工具命令语言
cups==commandunixprintingsystem##unix命令打印系统
apt==advancedpackagingtool##先进的包装工具
bg==background##背景、隐藏位置
fg==foreground##前景
ping==packetinternetgrouper##网络检测
--------------------------------------------------------------------------------------
如果首字母后为h,通常为改变的意思,需要保留
chsh==changeshell
chmod==changemode##更改模式
chown==changeowner##更改所有者
chgrp==changegroup##变更群组
bash==bourneagainshell##
zsh==zshell##
ksh==kornshell##
ssh==secureshell##安全命令
---------------------------------------------------------------------------------------
递归缩写类
gnu==gnuisnotunix##
php==phphypertextpreprocessor##
RPM==RPMpackagemanager
WINE==WINEisnotanemulator##
PNG==PNGisnotGIF##
nano==nanoisanothereditor##nano是另一个编辑器
如何更改linux文件的拥有者及用户组
使用命令chown
基本格式
chown user:[group] file
其中user为用户名,group为用户组名,file为文件或者文件夹,[]中的内容表示可选。
简单例子与说明:
chown user1:group1 file1
把当前文件夹下的file1的所有者改为user1,所有者用户组改为group1
下面为chown命令的详细,请参考:
Linux chown命令详解使用格式和方法
指令名称: chown使用权限: root
使用方式: chown [-cfhvR] [--help] [--version] user[:group] file…
利用 chown可以将档案的拥有者加以改变。这个指令只有是由系统管理者(root)所使用,一般使用者没有权限可以改变别人的档案拥有者,也没有权限可以自己的档案拥有者改设为别人。只有系统管理者(root)才有这样的权限。
参数:
-c或-change:作用与-v相似,但只传回修改的部分
-f或–quiet或–silent:不显示错误信息
-h或–no-dereference:只对符号链接的文件做修改,而不更改其他任何相关文件
-R或-recursive:递归处理,将指定目录下的所有文件及子目录一并处理
-v或–verbose:显示指令执行过程
–dereference:作用和-h刚好相反
–help:显示在线说明
–reference=<参考文件或目录>:把指定文件或目录的所有者与所属组,统统设置成和参考文件或目录的所有者与所属组相同
–version:显示版本信息
chown命令使用举例:(像我用的vps,就要先ssh登录)
# chown [-R] [用户名称] [文件或目录]
# chown[-R] [用户名称:组名称] [文件或目录]
范例1:将test3.txt文件的属主改为test用户。
# ls-l test3.txt
-rw-r–r– 1 test root 0 2009-10-23 9:59 test3.txt
# chown test:root test3.txt
# ls-l test3.txt
-rw-r–r– 1 test root 0 2009-10-23 9:59
范例2:chown所接的新的属主和新的属组之间可以使用:连接,属主和属组之一可以为空。如果属主为空,应该是“:属组”;如果属组为空,“:”可以不用带上。
# ls-l test3.txt
-rw-r–r– 1 test root 0 2009-10-23 9:59 test3.txt
# chown:test test3.txt<==把文件test3.txt的属组改为test
# ls-l test3.txt
-rw-r–r– 1 test test 0 2009-10-23 9:59 test3.txt
范例3:chown也提供了-R参数,这个参数对目录改变属主和属组极为有用,可以通过加-R参数来改变某个目录下的所有文件到新的属主或属组。
# ls-l testdir<==查看testdir目录属性
drwxr-xr-x 2 usr root 0 2009-10-56 10:38 testdir/<==文件属主是usr用户,属组是 root用户
# ls-lr testdir<==查看testdir目录下所有文件及其属性
total 0
-rw-r–r– 1 usr root 0 2009-10-23 10:38 test1.txt
-rw-r–r– 1 usr root 0 2009-10-23 10:38 test2.txt
-rw-r–r– 1 usr root 0 2009-10-23 10:38 test3.txt
# chown-R test:test testdir/<==修改testdir及它的下级目录和所有文件到新的用户和用户组
# ls-l testdir
drwxr-xr-x 2 test test 0 2009-10-23 10:38 testdir/
# ls-lr testdir
total 0
-rw-r–r– 1 test test 0 2009-10-23 10:38 test1.txt
-rw-r–r– 1 test test 0 2009-10-23 10:38 test2.txt
-rw-r–r– 1 test test 0 2009-10-23 10:38 test3.txt
Linux 中附属组和主组的区别
在使用useradd命令创建用户的时侯可以用-g和-G指定用户所属组和附属组。
基本组:如果没有指定用户组,创建用户的时候系统会默认同时创建一个和这个用户名同名的组,这个组就是基本组,不可以把用户从基本组中删除。在创建文件时,文件的所属组就是用户的基本组。
附加组:除了基本组之外,用户所在的其他组,都是附加组。用户是可以从附加组中被删除的。
用户不论为与基本组中还是附加组中,就会拥有该组的权限。一个用户可以属于多个附加组。但是一个用户只能有一个基本组。