Linux /etc/passwd /etc/group /etc/shadow 文件的格式说明

/etc/passwd 存放账户信息:

root:x:0:0:root:/root:/bin/bash
jianing:x:1011:100::/home/jianing:/bin/bash
<wbr><div> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> username:password:uid:gid:allname:homedir:shell</p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> 用户名:密码:用户ID:组ID:用户全名:主目录:登录shell</p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> 密码:存在/etc/shadow中,存入后者的就用x表示,如果是“!”说明此用户不能用密码登录</p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> UID:就是用户识别码(ID),当UID为0时说明其账号是管理员身份,1-499是保留给系统使用的主要是一些系统服务,500-65535是给一般用户的。</p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> GID:与/etc/group文件有关,就是用户初始化组的ID。</p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> 用户全名:用户全名</p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> </p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> 家目录:就是该用户的主目录</p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> Shell:SHELL脚本</p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> <br style="line-height:25px"></p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> <span style="font-size:18px; line-height:32px"><strong>/etc/shadow 存放用户密码</strong></span></p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> <span style="font-size:18px; line-height:32px"><strong><br></strong></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; font-size:12px; color:#333333; line-height:28px">root:$2a$32$3lnW8AXwIZy.Ibh0T2k3huMil/ZGEOQwe3EvJJzfnIcnPzxTamjke:14916::::::</span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"></span></p> <p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; font-size:12px"> <span style="font-family:宋体,Arial; color:#333333">jianing:$2a$10$AmxqDaxMITQoEr4HGcM/zO6JzJWMVcHpxmXdWKVOX5Tb/WWQ/m8wK:14853:0:99999:7:::</span></p> <p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; font-size:12px"> <span style="font-family:宋体,Arial; color:#333333">aj:!:15006:0:99999:7:::</span></p> <p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; font-size:12px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px; font-size:14px">username:password:last_change:min_change:max_change:warm:failed_expire:expiration:reserved</span></span></p> <p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; font-size:12px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px; font-size:14px">账号名称:</span><span style="line-height:19px; font-size:14px">密码:</span><span style="line-height:19px; font-size:14px">最近更改密码的日期(from 1974-1-1):</span><span style="line-height:19px; font-size:14px">密码不可更改的天数:</span><span style="line-height:19px; font-size:14px">密码需要重新更改的天数:</span><span style="line-height:19px; font-size:14px">密码更改期限前的警告日期:</span><span style="line-height:19px; font-size:14px">密码过期的宽限时间:</span><span style="line-height:19px; font-size:14px">账号失效时间:</span><span style="line-height:19px; font-size:14px">保留</span></span></p> <p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; font-size:12px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px; font-size:14px"><br style="line-height:25px"></span></span></p> <p style="line-height:23px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; font-size:12px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px; font-size:14px"><br style="line-height:25px"></span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px"><span style="font-size:18px; line-height:32px"><strong>/etc/group 用户组信息</strong></span></span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> </p> <p style="line-height:19px; margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); font-family:宋体,Arial"> <br style="line-height:25px"></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333">root:x:0:</span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333">test:!:1005:u01,u02,u03,cvsroot</span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px">groupname:password:gid:members</span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px"><br style="line-height:25px"></span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px">组名:密码:组ID:成员</span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px"><br></span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px"><br></span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px"><br></span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px"><br></span></span></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px"></span></span></p> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <strong>linux用户和/etc/passwd文件</strong> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> passwd文件是以行为单位的配置文件,每行定义系统上的一个用户,行内分为字段,字段之间由一个冒号隔开。这些字段依次为:</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> 用户名:密码:用户ID:主要组ID:GECOS:主目录:登录shell</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#993300">字段解释:</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#000000"><span style="color:#800000">用户名:</span>就是一个用户名,登录时候用的</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#000000"><span style="color:#800000">密码:</span>在旧的UNIX系统上,这个字段含有用户的加密密码,为了安全性,现在的linux均显示为x或*号</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#000000"><span style="color:#800000">用户ID:</span>linux内核用于识别用户的一个整数ID</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#000000"><span style="color:#800000">主要组ID:</span>linux内核用于识别用户主要组的一个整数ID</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#000000"><span style="color:#800000">GECOS:</span>用户全名,安装linux时如果不输入全名,则显示为跟用户名一样,如果输入,则显示为全名(不可用于登录)</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#000000"><span style="color:#800000">主目录:</span>用户登录时,他的登录Shell将使用这个目录作为当前工作目录</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#000000"><span style="color:#800000">登录Shell:</span>用户登录时的默认Shell,在redhat 企业版中,登录shell通常是/bin/bash</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> <span style="color:#000000"></span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> 一个/etc/passwd文件中的典型几行数据</div> <span style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"></span> <div style="color:rgb(0,0,0)"> <span style="color:rgb(136,0,0)">root:x:0:0:root:/root:/bin/bash</span><br><span style="color:rgb(136,0,0)">apache:x:48:48:Apache:/var/www:/sbin/nologin</span> </div> <div>tomcat:x:91:91:Apache Tomcat:/usr/share/tomcat6:/bin/sh</div> <span style="font-family:arial; font-size:14px; line-height:23px; background-color:rgb(241,241,241)"></span> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> 说明:第2个字段用户加密后的密码在现代linux中不显示的,显示为"x"或"*"号</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> 如需了解passwd详细信息,可运行man 5 passwd<span style="color:rgb(0,0,0)">命令</span>来查看</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <strong>linux用户密码和/etc/shadow文件</strong> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> 以前用户的加密都是被保存在/etc/passwd文件中的第2个字段中,并且每个用户都可以读取,随着计算机性能的发展,暴力破解变得相对比较容易,因此,现在linux采用一种“影子密码”,用户的密码被保存在专门的/etc/shadow文件中,其权限不允许普通用户查看,root用户可以查看,了解详细信息可执行man 5 shadow。</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> /etc/shadow 文件信息存储结构,字段依次为</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> 用户名:加密密码:上次更改密码的时间:最小更改密码间隔:密码有效期限:密码过期提示时间:密码锁定期:账户有效期:保留字段</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> /etc/shadow文件中几行数据</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <span style="color:rgb(136,0,0)">root:$6$DgEqy0v1u0STl/ML$lmRzdT/Ad6PoNmahItTnvc1NwoBlvSLEriBDXyE4rhTGpFHweMTe/GkW5bSsAsVQjMLrsDAY5X.jr8NsE1Ekh1:15148:0:99999:7:::<br> lzgonline:$6$2ji/.tNs9lWLcAQu$dCsR22xAxHj6q9rDSE1w14KeflWmvS5.RDD2ro11/H55TIkM69ghyPZgazi.egaTuQhIWWgLPZMvcuSKb3vFs/:15148:0:99999:7:::<br> apache:!!:15148::::::</span><br> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> 用户使用passwd命令更改密码时,如果不是root用户,则passwd不接受任何参数和选项,即用户只能更改自己的密码。</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <strong>3种类型的用户</strong> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <span style="color:#800000">普通用户</span>:普通用户是使用系统真实用户人群。普通用户通常把/bin/bash作为登录Shell和/home的子目录作为主目录。一般情况下,普通用户只在自己的主目录和系统范围内的临时目录里(如/tmp和/var/tmp)创建文件。在redhat企业版linux中,普通用户的用户ID数通常大于500.</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <span style="color:#800000">root用户</span>:用户ID为0的用户,也被称为超级用户,root用户在系统上拥有完全权限,可以修改和删除任何文件,可以运行任何命令,可以取消任何进程。root用户负责增加和保留其他用户、配置硬件、添加系统软件。虽然root用户可以在系统上的任何地方创建文件,但它也通常使用/root作为主目录</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <span style="color:#800000">系统用户</span>:大多数linux系统保留一系列低UID值用户作为系统用户,系统用户不代表人,而代表系统的组成部分。例如,运行Apache网络服务器的进程经常作为用户apache(<span style="color:rgb(136,0,0)">见上面的passwd文件中apache用户信息</span>)来运行。系统用户一般没有登录Shell,因为它不代表实际登录的用户。同样,系统用户的主目录很少在/home中,而通常在属于相关应用的系统目录中。例如,用户apache的主目录是/var/www。在redhat企业版linux中,系统用户的UID值范围在1-499之间。</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <strong>操作中常用linux命令</strong> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241); color:rgb(136,0,0)"> ps -aux //检查进程用户ID</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND<br> root 1 0.0 0.1 2824 1408 ? Ss 22:27 0:01 /sbin/init<br> root 2 0.0 0.0 0 0 ? S 22:27 0:00 [kthreadd]<br> root 3 0.0 0.0 0 0 ? S 22:27 0:00 [migration/0]<br> root 4 0.0 0.0 0 0 ? S 22:27 0:00 [ksoftirqd/0]</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <span style="color:rgb(136,0,0)"><br> ls -l //根据用户名列出目录所有者</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> [root@lzgonline lzgonline]# ls -l<br> 总用量 36<br> drwxrwxr-x. 2 lzgonline lzgonline 4096 6月 23 22:50 coding<br> drwxr-xr-x. 2 lzgonline lzgonline 4096 6月 23 22:03 公共的<br> drwxr-xr-x. 2 lzgonline lzgonline 4096 6月 23 22:03 模板<br> drwxr-xr-x. 2 lzgonline lzgonline 4096 6月 23 22:03 视频</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> <br><span style="color:rgb(136,0,0)">ls -ln //根据用户ID列出目录所有者</span> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> [root@lzgonline lzgonline]# ls -ln<br> 总用量 36<br> drwxrwxr-x. 2 500 500 4096 6月 23 22:50 coding<br> drwxr-xr-x. 2 500 500 4096 6月 23 22:03 公共的<br> drwxr-xr-x. 2 500 500 4096 6月 23 22:03 模板<br> drwxr-xr-x. 2 500 500 4096 6月 23 22:03 视频<br> drwxr-xr-x. 2 500 500 4096 6月 23 22:03 图片</div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> </div> <div style="line-height:25px; font-family:arial; font-size:14px; background-color:rgb(241,241,241)"> 说明:linux内核不保存拥有文件的用户的用户名,保存的是用户ID,每次ls命令运行时,必须在/etc/passwd文件中查找用户名与用户ID映射,然后把用户名对应到内核所提供的用户ID上。</div> <br><p></p> <p style="margin-top:0px; margin-bottom:10px; padding-top:0px; padding-bottom:0px"> <span style="font-family:宋体,Arial; color:#333333"><span style="line-height:19px"><br></span></span></p> </div> </wbr>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值