📄 linux 用户(user)查询篇 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=(0040)http://www.linuxsir.org/main/?q=node/105 -->
<HTML lang=zh-hans xml:lang="zh-hans"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Linux 用户(User)查询篇 | 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="Linux 用户(User)查询篇 LinuxSir_Org.files/menuExpandable3.css" type=text/css
rel=stylesheet>
<SCRIPT src="Linux 用户(User)查询篇 LinuxSir_Org.files/menuExpandable3.js"
type=text/javascript></SCRIPT>
<LINK href="Linux 用户(User)查询篇 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="Linux 用户(User)查询篇 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 和 68 游客 在线</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>Linux 用户(User)查询篇</H2><!-- begin content -->
<DIV class=node>
<DIV class=content>
<P><B>作者:</B>北南南北<BR><B>赞助:</B><BR><B>来自:</B>LinuxSir.Org<BR><B>摘要:</B>
本文主要介绍在用户管理中,查询用户的几种工具介绍 id 、finger、groups 以及 w、who、users ;</P>
<P><FONT size=4><B><BR>目录索引<BR></B></FONT></P>
<P><B><A
href="http://www.linuxsir.org/main/?q=node/105#1">一、用户查询工具的原理;</A></B>
</P>
<P><A
href="http://www.linuxsir.org/main/?q=node/105#2">二、用户(User)和用户组(Group)查询工具;</A></B>
</P>
<UL><A href="http://www.linuxsir.org/main/?q=node/105#2.1">1、id 工具:
查询用户所对应的UID 和GID 及GID所对应的用户组;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/105#2.2">2、finger
工具:用来查询用户信息,侧重用户家目录、登录SHELL等;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/105#2.3">3、查询登录主机的用户工具:w 、who
、users </A><BR><A
href="http://www.linuxsir.org/main/?q=node/105#2.4">4、groups
用户所归属的用户组查询;</A> </UL>
<P><B><A
href="http://www.linuxsir.org/main/?q=node/105#3">三、后记;</A></B><BR><B><A
href="http://www.linuxsir.org/main/?q=node/105#4">四、参与修正本文;</A></B><BR><B><A
href="http://www.linuxsir.org/main/?q=node/105#5">五、致谢;</A></B><BR><B><A
href="http://www.linuxsir.org/main/?q=node/105#6">六、相关文档;</A></B> </P>
<P><FONT
color=blue><B><BR>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>正文<BR>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR></B></FONT></P>
<P><FONT id=1 size=4><B><BR>一、用户查询工具的原理;<BR></B></FONT></P>
<P>在用户管理中,用户查询是通过几个常用的工具来完成的,比如id 、finger、groups、users ... ...
,我们都知道用户的配置文件是/etc/passwd,用户组的配置文件是/etc/groups
文件,我们对用户的查询除了通过查询工具以外,我们还能直接查看用户和用户组的配置文件来达到查询的目的; </P>
<P>用户查询工具的原理也是读取与用户和用户组有关的配置文件,然后按一定的规则和条件输出,用户和用户组配置文件很重要,所以您有必要先读一下关有用户管理的文档:</P>
<P><A href="http://www.linuxsir.org/main/?q=node/91">《Linux
用户(user)和用户组(group)管理概述》</A><BR><A
href="http://www.linuxsir.org/main/?q=node/98">《用户(user)和用户组(group)配置文件详解》</A></P>
<P><FONT id=2 size=4><B><BR>二、用户(User)和用户组(Group)查询工具;<BR></B></FONT></P>
<P><FONT id=2.1 size=3><B><BR>1、id 工具: 查询用户所对应的UID 和GID
及GID所对应的用户组;<BR></B></FONT><BR>id 工具是用来查询用户信息,比如用户所归属的用户组,UID 和GID等;id
用法极为简单;我们举个例子说明一下;</P>
<P>
<DIV class=codeblock><CODE>语法格式: id [参数] [用户名]</CODE></DIV>
<P></P>
<P>至于有哪些参数,自己查一下 id --help 或man id
;如果id后面不接任何参数和任何用户,默认显示当前操作用户的用户名、所归属的用户组、UID和GID等;<BR><B><BR>实例一:不加任何参数和用户名;<BR></B><BR>
<DIV class=codeblock><CODE>[beinan@localhost ~]$ id<BR>uid=500(beinan)
gid=500(beinan) groups=500(beinan)</CODE></DIV>
<P></P>
<P><B>注解:</B>在没有加任何参数的情况下,查询的是当前操作用户的用户名、UID 、GID
和所处的主用户组和附属用户组;在本例中,用户名是beinan,UID是500,所归属的主用户组是beinan,GID是500 ;</P>
<P><B><BR>实例二: id 后面接用户名;<BR></B><BR>如果我们想查询系统中用户的UID和GID
相应的内容,可以直接接用户名,但用户名必须是真实的 ,能在/etc/passwd中查到的;<BR>
<DIV class=codeblock><CODE>[beinan@localhost ~]$ id
linuxsir<BR>uid=505(linuxsir) gid=502(linuxsir)
groups=502(linuxsir),0(root),500(beinan)</CODE></DIV>
<P></P>
<P><B>注解:</B>查询用户linuxsir 的信息,用户linuxsir ,UID
为505,所归属的主用户组是linuxsir,主用户组的GID是502;同时linuxsir用户也是GID为0的root用户组成员,也是GID为500用户组beinan的成员;</P>
<P>这个例子和实例一在用户组方面有所不同,我们在 <A
href="http://www.linuxsir.org/main/?q=node/91">《Linux
用户(user)和用户组(group)管理概述》</A>
中有提到;用户和用户组的对应关系,可以是一对一、一对多、多对一、或多对多的交叉关系,请参考之;另外您还需要掌握<A
href="http://www.linuxsir.org/main/?q=node/98">《用户(user)和用户组(group)配置文件详解》</A>一文;</P>
<P><FONT id=2.2 size=3><B><BR>2、finger
工具:用来查询用户信息,侧重用户家目录、登录SHELL等;<BR></B></FONT><BR>finger
工具侧重于用户信息的查询;查询的内容包括用户名(也被称为登录名Login),家目录,用户真实的名字(Name)... ...
办公地址、办公电话;也包括登录终端、写状态、空闭时间等;</P>
<P>我们最常用finger 来查询用户家目录、用户真实名、所用SHELL 类型、以及办公地址和电话,这是以参数 -l
长格式输出的;而修改用户的家目录、真实名字、办公地址及办公电话,我们一般要能过chfn命令进行;</P>
<P><B><BR>语法格式:<BR></B><BR></CODE><BR>finger [参数选项] [用户名]<BR>-l
采用长格式(默认),显示由-s选项所包含的所有信息,以及主目录、办公地址、办公电话、登录SHELL、邮件状态、.plan、.project和.forward;<BR>-m
禁止对用户真实名字进行匹配;<BR>-p 把.plan和.project文件中的内容省略;<BR>-s
显示短格式,用户名(也被称为登录名Login)、真实名字(NAME)、在哪个终端登录(Tty)、写状态、空闲时间(Idle)、登录时间(Login
Time)、办公地点、办公电话等;</P>
<P></CODE></P>
<P>至于finger 有哪些参数,您可以通过 finger --help 或man finger
来获取,我们在本文中以实例讲述最常用的参数;</P>
<P><B><BR>实例一:不接任何参数,也不指定查询用户名;默认为加了-s参数;<BR></B><BR>
<DIV class=codeblock><CODE>[beinan@localhost ~]$ finger<BR>Login Name Tty
Idle Login Time Office Office Phone<BR>beinan beinan sun tty1 1:39 Nov 2
08:27<BR>linuxsir linuxsir open tty2 2 Nov 2 10:03 linuxsir o
+1-389-866-771</CODE></DIV>
<P></P>
<P>等价命令 </P>
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -