📄 用户(user)和用户组(group)配置文件详解 linuxsir_org.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0039)http://www.linuxsir.org/main/?q=node/98 -->
<HTML lang=zh-hans xml:lang="zh-hans"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>用户(User)和用户组(Group)配置文件详解 | LinuxSir.Org</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE type=text/css media=all>@import url( misc/drupal.css );
</STYLE>
<STYLE type=text/css media=all>@import url( modules/taxonomy_context/taxonomy_context.css );
</STYLE>
<LINK media=screen
href="用户(User)和用户组(Group)配置文件详解 LinuxSir_Org.files/menuExpandable3.css"
type=text/css rel=stylesheet>
<SCRIPT src="用户(User)和用户组(Group)配置文件详解 LinuxSir_Org.files/menuExpandable3.js"
type=text/javascript></SCRIPT>
<LINK href="用户(User)和用户组(Group)配置文件详解 LinuxSir_Org.files/common.css"
type=text/css rel=stylesheet>
<STYLE type=text/css media=all>@import url( themes/chameleon/marvin/style.css );
</STYLE>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY>
<DIV id=header><A title=Home href="http://www.linuxsir.org/main/"><IMG alt=Home
src="用户(User)和用户组(Group)配置文件详解 LinuxSir_Org.files/logo.jpg"></A></DIV>
<DIV class=navlinks>
<DIV class=primary><A href="http://www.linuxsir.org/main/?q"><FONT
color=white>首页</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/34"><FONT
color=white>事件</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/1/25/"><FONT
color=white>文档</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/35/48/"><FONT
color=white>资源</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=search"><FONT color=white>搜索</FONT></A> |
<A href="http://www.linuxsir.org/bbs"><FONT color=white>论坛</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/38"><FONT
color=white>贡献者</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=node/3"><FONT color=white>关于</FONT></A> |
<A href="http://www.linuxsir.org/main/?q=user"><FONT
color=white>注册/登录</FONT></A></DIV></DIV>
<TABLE id=content>
<TBODY>
<TR>
<TD id=sidebar-left>
<DIV class="block block-block" id=block-block-1>
<H2 class=title>子站索引</H2>
<DIV class=content>
<UL>
<LI><A href="http://fedora.linuxsir.org/" target?_blank?>Fedora中文</A>
<LI><A href="http://debian.linuxsir.org/" target?_blank?>Debian中文</A>
<LI><A href="http://lfs.linuxsir.org/" target?_blank?>LFS 中文</A>
<LI><A href="http://slack.linuxsir.org/">Slackware</A>
<LI><A href="http://gentoo.linuxsir.org/">Gentoo中文</A>
<LI><A href="http://arch.linuxsir.org/">Arch 中文</A> </LI></UL></DIV></DIV>
<DIV class="block block-block" id=block-block-3>
<H2 class=title>重要资讯</H2>
<DIV class=content>
<UL>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/36">本站公告</A>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/34">新闻事件</A>
<LI><A href="http://www.linuxsir.org/bbs" target=_blank>本站论坛</A>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/38">贡 献 者</A>
</LI></UL></DIV></DIV>
<DIV class="block block-block" id=block-block-7>
<H2 class=title>项目索引</H2>
<DIV class=content>
<UL>
<LI><A href="http://www.fcitx.org/" target=_blank>小企鹅输入法</A>
<LI><A href="http://lumaqq.linuxsir.org/" target=_blank>LumaQQ</A>
<LI><A href="http://openq.linuxsir.org/" target=_blank>OpenQ</A>
<LI><A href="http://www.relaxbsd.org/" target=_blank>RelaxBSD</A>
</LI></UL></DIV></DIV>
<DIV class="block block-user" id=block-user-1>
<H2 class=title>站点导航</H2>
<DIV class=content>
<DIV class=menu>
<UL>
<LI class=leaf><A title=注册/登录
href="http://www.linuxsir.org/main/?q=user">注册/登录</A>
<LI class=collapsed><A
href="http://www.linuxsir.org/main/?q=aggregator">新闻聚合</A>
</LI></UL></DIV></DIV></DIV>
<DIV class="block block-aggregator" id=block-aggregator-feed-2>
<H2 class=title>LinuxSir.Org 论坛</H2>
<DIV class=content>
<DIV class=item-list>
<UL>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266922&goto=newpost">如何在FvwmButtons中使用系统托盘?</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266921&goto=newpost">FC5
root 的垃圾箱被彻底删掉了,怎么恢复?</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266920&goto=newpost">我想做一个mini
linux 该怎么下手呢~</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266919&goto=newpost">FC5体验之影音篇</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266918&goto=newpost">请教高手:FEDORA
4 安装问题</A> </LI></UL></DIV>
<DIV class=more-link><A title=查看此feed的最新消息
href="http://www.linuxsir.org/main/?q=aggregator/sources/2">更多</A></DIV></DIV></DIV>
<DIV class="block block-user" id=block-user-2>
<H2 class=title>最新注册</H2>
<DIV class=content>
<DIV class=item-list>
<UL>
<LI>horiwa
<LI>jiechu
<LI>emiss
<LI>ismart
<LI>mynamewsy</LI></UL></DIV></DIV></DIV>
<DIV class="block block-user" id=block-user-3>
<H2 class=title>当前在线</H2>
<DIV class=content>0 users 和 66 游客 在线</DIV></DIV></TD>
<TD id=main>
<DIV class=breadcrumb><A href="http://www.linuxsir.org/main/?q=">首页</A> »
<A href="http://www.linuxsir.org/main/?q=taxonomy/term/1">Linux</A></DIV>
<H2>用户(User)和用户组(Group)配置文件详解</H2><!-- begin content -->
<DIV class=node>
<DIV class=content>
<P><B>作者:</B>北南南北<BR><B>来自:</B>LinuxSir.Org<BR><B>摘要:</B>本文详解用户(User)和用户组(Group)的配置文件,本文是<A
href="http://www.linuxsir.org/main/?q=node/91">《Linux
用户(User)和用户组(Group)管理概述》</A>文档的关健部份的细化;通过本文,您至少能明白/etc/passwd /etc/group
,以及什么是UID和GID
等;其中对UID的重要性加以详细的论述;最后,本文还以通过修改用户及用户组配置文件的办法来实现管理用户和用户组,进而说明在Linux系统中,系统文件的重要性;</P>
<P><FONT
color=blue><B><BR>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>正文<BR>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR></B></FONT></P>
<P>用户(User)和用户组(Group)的配置文件,是系统管理员最应该了解和掌握的系统基础文件之一,从另一方面来说,了解这些文件也是系统安全管理的重要组成部份;做为一个合格的系统管理员应该对用户和用户组配置文件透彻了解才行;</P>
<P><FONT size=4><B><BR>一、用户(User)相关;<BR></B></FONT></P>
<P>谈到用户,就不得不谈用户管理,用户配置文件,以及用户查询和管理的控制工具;用户管理主要通过修改用户配置文件完成;用户管理控制工具最终目的也是为了修改用户配置文件。</P>
<P>什么是用户查询和管理控制工具呢?用户查询和控制工具是查询、添加、修改和删除用户等系统管理工具,比如查询用户的id和finger命令,添加用户的useradd
或adduser 、userdel 用户的删除 、设置密码的passwd命令 、修改用户usermod
等等;我们需要知道的是通过用户查询和控制工具所进行的动作的最终目的也是修改用户配置文件;所以我们进行用户管理的时候,直接修改用户配置文件一样可以达到用户管理的目的;</P>
<P>通过上面的解说,我们能实实在在的感觉到用户(User)配置文件的重要性;其实用户和用户组在系统管理中是不可分割的,但为了说明问题,我们还是得把用户(User)的配置文件单列出来解说,其中包括/etc/passwd
和/etc/shadow 文件;在这之中,你还能了解UID的重要性;</P>
<P>通过本标题,您可以了解或掌握的内容有:了解/etc/passwd和/etc/shadow;什么UID ;</P>
<P>与用户相关的系统配置文件主要有/etc/passwd
和/etc/shadow,其中/etc/shadow是用户资讯的加密文件,比如用户的密码口令的加密保存等;/etc/passwd
和/etc/shadow 文件是互补的;我们可以通过对比两个文件来差看他们的区别;<BR><FONT
size=3><B><BR>1、关于/etc/passwd 和 UID;<BR></B></FONT></P>
<P>/etc/passwd 是系统识别用户的一个文件,做个不恰当的比喻,/etc/passwd
是一个花名册,系统所有的用户都在这里有登录记载;当我们以beinan 这个账号登录时,系统首先会查阅 /etc/passwd
文件,看是否有beinan 这个账号,然后确定beinan的UID,通过UID 来确认用户和身份,如果存在则读取/etc/shadow
影子文件中所对应的beinan的密码;如果密码核实无误则登录系统,读取用户的配置文件;<BR><FONT
size=2><B><BR>1)/etc/passwd 的内容理解:<BR></B></FONT></P>
<P>在/etc/passwd 中,每一行都表示的是一个用户的信息;一行有7个段位;每个段位用:号分割,比如下面是我的系统中的/etc/passwd
的两行;<BR><BR><BR>
<DIV class=codeblock><CODE>beinan:x:500:500:beinan
sun:/home/beinan:/bin/bash<BR>linuxsir:x:505:502:linuxsir open,linuxsir
office,13898667715:/home/linuxsir:/bin/bash<BR>beinan:x:500:500:beinan
sun:/home/beinan:/bin/bash<BR>linuxsir:x:501:502::/home/linuxsir:/bin/bash</CODE></DIV>
<P></P>
<P><B>第一字段:</B>用户名(也被称为登录名);在上面的例子中,我们看到这两个用户的用户名分别是 beinan
和linuxsir;<BR><B>第二字段:</B>口令;在例子中我们看到的是一个x,其实密码已被映射到/etc/shadow
文件中;<BR><B>第三字段:</B>UID
;请参看本文的UID的解说;<BR><B>第四字段:</B>GID;请参看本文的GID的解说;<BR><B>第五字段:</B>用户名全称,这是可选的,可以不设置,在beinan这个用户中,用户的全称是beinan
sun ;而linuxsir 这个用户是没有设置全称;<BR><B>第六字段:</B>用户的家目录所在位置;beinan
这个用户是/home/beinan ,而linuxsir 这个用户是/home/linuxsir
;<BR><B>第七字段:</B>用户所用SHELL 的类型,beinan和linuxsir 都用的是 bash ;所以设置为/bin/bash
;</P>
<P><FONT size=2><B><BR>2)关于UID 的理解:<BR></B></FONT></P>
<P>UID 是用户的ID 值,在系统中每个用户的UID的值是唯一的,更确切的说每个用户都要对应一个唯一的UID
,系统管理员应该确保这一规则。系统用户的UID的值从0开始,是一个正整数,至于最大值可以在/etc/login.defs
可以查到,一般Linux发行版约定为60000; 在Linux 中,root的UID是0,拥有系统最高权限;</P>
<P>UID 在系统唯一特性,做为系统管理员应该确保这一标准,UID 的唯一性关系到系统的安全,应该值得我们关注!比如我在/etc/passwd
中把beinan的UID
改为0后,你设想会发生什么呢?beinan这个用户会被确认为root用户。beinan这个帐号可以进行所有root的操作;</P>
<P><B><BR>UID 是确认用户权限的标识,用户登录系统所处的角色是通过UID 来实现的,而非用户名,切记;把几个用户共用一个UID
是危险的,比如我们上面所谈到的,把普通用户的UID 改为0,和root共用一个UID
,这事实上就造成了系统管理权限的混乱。如果我们想用root权限,可以通过su或sudo来实现;切不可随意让一个用户和root分享同一个UID
;<BR></B></P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -