Loading... <p></p> <p>本节介绍Linux用户和组相关的配置文件,用户账号管理、查询用户信息以及切换用户的相关命令,<span style="line-height: 1.5">将会让我们更了解各配置文件中各个字段的含义,以及各相关命令的使用方法,</span><span style="line-height: 1.5">方便Linux运维人员管理Linux系统中的用户和组。</span></p> <p><span style="line-height: 1.5"><br /></span></p> <p><span style="line-height: 1.5">背景:</span></p> <p><span style="line-height: 1.5">Linux是个多用户、多任务的系统,考虑到每个人的隐私权、每个人喜好的工作环境以及每个用户所使用的权限等方面的不同,所以设定了“用户”来管理各自用户的权限。</span></p> <p></p> <p>一、用户和用户组相关的配置文件管理</p> <ul class=" list-paddingleft-2"> <li> <p><span style="line-height: 1.5">/etc/passwd:用户的账号信息 </span></p> </li> <li> <p>/etc/group:组的账号信息</p> </li> <li> <p><span style="line-height: 1.5">/etc/shadow:用户密码和相关的账号设定</span></p> </li> <li> <p><span style="line-height: 1.5">/etc/gshadow:组的密码信息</span></p> </li> </ul> <p><span style="line-height: 1.5"> (1)/etc/passwd文件</span></p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <p><span style="line-height: 1.5"> 文件中共包含了7个字段,分别使用 : 隔开。下面介绍各个字段所代表的含义</span></p> <p><span style="line-height: 1.5"> account : password : UID : GID : GECOS : directory : shell</span></p> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="line-height: 1.5"> 登陆名 : 密码符 : 用户ID : 组ID : 注释信息 : 家目录 : 用户默认shell</span></p></blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px">备注:用户可以加入不止一个组:基本组一个,附加组(也称额外组)可包含多个。</p></blockquote> </blockquote> </blockquote> </blockquote> <p> (2)/etc/group</p> <p> 文件中共包含了4个字段,分别使用 : 隔开。下面介绍各个字段所代表的含义</p> <p> group_name : passwd : GID : user_list</p> <p> 组名 : 密码符 : GID : 以都好分割属于此组(以之作为额外组)的用户列表</p> <p> (3)/etc/shadow</p> <p> 文件中共包含了7个字段,分别使用 : 隔开。下面介绍各个字段所代表的含义</p> <p> 用户名 : 加密的密码 : 最近一次修改密码的时间 : 密码最短使用期限 : 密码最长使用期限 : 密码过期警告区间 : 密码非活动期限 : 账号过期期限 : 保留区域</p> <p> (4)/etc/gshaow </p> <p> 文件中共包含了4个字段,分别使用 : 隔开。下面介绍各个字段所代表的含义</p> <p> group_name : password : administrator : members</p> <p> 组名 : 密码符 : 用户组的管理员 : 组的成员 </p> <p>二、用户账号管理相关命令(这里仅列出去常用命令和参数,详细请查man)</p> <ul class=" list-paddingleft-2"> <li> <p><span style="line-height: 1.5">useradd :新增用户</span></p> </li> <li> <p><span style="line-height: 1.5">groupadd :新增组</span></p> </li> <li> <p><span style="line-height: 1.5">passwd :修改用户密码</span></p> </li> <li> <p>gpasswd :修改组密码</p> </li> <li> <p><span style="line-height: 1.5">userdel :删除用户</span></p> </li> <li> <p><span style="line-height: 1.5">groupdel :删除组</span></p> </li> <li> <p><span style="line-height: 1.5">usermod :修改用户账号</span></p> </li> <li> <p>groupmod :修改组账号</p> </li> <li> <p><span style="line-height: 1.5">chsh :修改用户的shell</span></p> </li> <li> <p><span style="line-height: 1.5">chfn :修改注释信息</span></p> </li> <li> <p><span style="line-height: 1.5">chage :修改密码时效</span></p> </li> </ul> <p> (1)useradd</p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> -u UID :指定UID</p></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -g GID :指定所属的基本组</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -G GID : 指定所属的附加组 </p> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> -c 'COMMENT' :注释信息</p></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -d /path/to/somewhere :指定家目录,如果此目录事先存在,会有警告信息</p> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> 备注:在家目录中其实会有一些文件</p></blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> 例如:ls -a /home/user1 ————> . .. .bash_logout .bash_profile .bashrc</p></blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> 这些文件是从系统/etc/skel 下拷贝过来的</p></blockquote> </blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> -s SHELL :指定SHELL,SHELL必须是在/etc/shells文件中存在的shell</p></blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> 备注 /etc/shells是系统中支持的shell</p></blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> 其中/sbin/nologin 表示不给用户登录 </p></blockquote> </blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> -m :强制给用户创建家目录</p></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -M :不给用户创建家目录</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -r :创建系统用户</p> </blockquote> </blockquote> <p> (2)groupadd</p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> -g GID:指定GID</p></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -r :系统组</p> </blockquote> </blockquote> <p> (3)passwd</p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px">普通用户仅能修改自己的密码</p></blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> 管理员 能修改全部用户的密码</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> passwd [username]</p></blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> –stdin : 不需要交互式输入密码</p></blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="line-height: 1.5"> -l :锁定用户</span></p></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p><span style="line-height: 1.5"> -u :解锁用户</span></p> </blockquote> </blockquote> <p> (4)gpasswd</p> <p> gpasswd[-a user][-d user][-A user,…][-M user,…][-r][-R]groupname</p> <p> -a:添加用户到组</p> <p> -d:从组删除用户</p> <p> -A:指定管理员</p> <p> -M:指定组成员和-A的用途差不多</p> <p> -r:删除密码</p> <p> -R:限制用户登入组,只有组中的成员才可以用newgrp加入该组</p> <p> 备注:给组账号设置完密码以后,用户登陆系统,使用newgrp命令,输入给组账号设置的密码,就可以临时添加到指定组,可以管理组用户,具有组权限。格式:newgrp 【组名】</p> <p> (5)userdel<span style="background-color: inherit"> </span></p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="background-color: inherit">userdel [options] USERNAME</span></p></blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="background-color: inherit"> -r: 一并删除用户及家目录</span></p></blockquote> </blockquote> <p> (6)groupdel</p> <p> groupdel GRPNAME</p> <p> (7)usermod</p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="line-height: 1.5">usermod [options] USERNAME </span></p></blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="line-height: 1.5"> -u UID : 修改UID </span></p></blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="line-height: 1.5"> -g GID :修改用户的基本组</span></p></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p><span style="line-height: 1.5"> -G GID,….:修改用户附加组;此选项通常跟-a一起使用,以最佳方式修改附加组,表示不覆盖原有的附加组</span></p> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="line-height: 1.5"> 例子:usermod -a -G mygrp,testgrp user6</span></p></blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><span style="line-height: 1.5"> -c COMMENT:指定注释信息</span></p></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p><span style="line-height: 1.5"> -d /path/to/somewhere :修改家目录的位置;同时使用-m选项可保证创建家目录,并将用户原有的文件移动至新的家目录中</span></p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p><span style="line-height: 1.5"> -s SHELL:修改SHELL</span></p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p><span style="line-height: 1.5"> -l LOGIN_NAME:修改用户名</span></p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p><span style="line-height: 1.5"> -L :锁定用户</span></p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -U :解锁用户</p> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> <p> (8)groupmod</p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> -g GID</p></blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> -n NEW_GRP_NAME</p></blockquote> </blockquote> <p> (9)chsh </p> <p> chsh USERNAME</p> <p> (10)chfn</p> <p> chfn USERNAME</p> <p> (11)chage</p> <p> chage[options] USERNAME</p> <p> 实例截图:</p> <p> (1)useradd</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163716-26.png" title="1433987139319712.png" /></p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703163716-2.png" title="1433987139485942.png" /></p> <p> (2)groupadd</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163716-94.png" title="1433992167289643.png" alt="3.png" /></p> <p> (3)passwd</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163716-83.png" title="1433987139970883.png" /></p> <p> (4)gpasswd</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703163716-44.png" title="1433987139319724.png" /></p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703163716-88.png" title="1433987139518178.png" /></p> <p><span style="line-height: 1.5"> (5)userdel</span><br style="background-color: inherit" /></p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163716-68.png" title="1433992229396406.png" alt="111.png" /></p> <p><span style="line-height: 1.5"><span style="line-height: 1.5"> (6)groupdel</span><br style="background-color: inherit" /></span></p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163716-54.png" title="1433992236750004.png" alt="222.png" /></p> <p><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"> (7)usermod</span><br style="background-color: inherit" /></span></span></p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163717-70.png" title="1433987139583415.png" /></p> <p><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"> (8)groupmod</span><br style="background-color: inherit" /></span></span></span></p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163717-62.png" title="1433987140741382.png" /></p> <p><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"> (9)chsh</span><br style="background-color: inherit" /></span></span></span></span></p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163717-48.png" title="1433987140794437.png" /></p> <p></p> <p><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"> (10)chfh</span><br style="background-color: inherit" /></span></span></span></span></span></p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163717-96.png" title="1433987140125299.png" /></p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163717-41.png" title="1433987140104197.png" /></p> <p><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"><span style="line-height: 1.5"> (11)chage</span><br style="background-color: inherit" /></span></span></span></span></span></span></p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /> <img src="//cto.wang/usr/uploads/2016/07/20160703163717-44.png" title="1433987140119233.png" /></p> <p>三、查询用户信息相关命令 </p> <ul class=" list-paddingleft-2"> <li> <p><span style="line-height: 1.5">id :显示用户信息</span></p> </li> <li> <p><span style="line-height: 1.5">who :显示目前登入系统的用户信息</span></p> </li> <li> <p><span style="line-height: 1.5">whoami :</span><span style="line-height: 1.5">显示自身的用户名称</span></p> </li> <li> <p><span style="line-height: 1.5">finger :查询用户的相信信息,例如用户的用户名、主目录、停滞时间、登录时间、登录shell等信息</span></p> </li> </ul> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p>(1)id</p> <p><span style="line-height: 1.5"> id USERNAME</span></p> </blockquote> <p><span style="line-height: 1.5"> -g:显示用户所属的基本组</span></p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -G:显示用户所有组(默认显示数字)</p> <p> -n:显示名称</p> <p> -u:显示UID</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p>(2)who</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> who [option]</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p> -H :显示各栏位</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p>(3)whoami</p> <p><span style="line-height: 1.5"> whoami [–help][–version] </span></p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p>(4)finger</p> <p><span style="line-height: 1.5"> finger [-lmsp] [user …] [</span><span style="line-height: 1.5">user@host</span><span style="line-height: 1.5"> …]</span></p> </blockquote> <p><span style="line-height: 1.5"> -l : 多行显示来描述信息,例如关于用户家目录,家庭电话,登录脚本等内容</span></p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p>实例截图:</p> <p>(1)id</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163717-58.png" title="1433987140163336.png" /></p> <p>(2)who</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /><img src="//cto.wang/usr/uploads/2016/07/20160703163717-4.png" title="1433987140659079.png" /></p> <p>(3)whoami</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /><img src="//cto.wang/usr/uploads/2016/07/20160703163717-13.png" title="1433987140102977.png" /></p> <p>(4)finger</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /><img src="//cto.wang/usr/uploads/2016/07/20160703163717-67.png" title="1433992319318552.png" alt="18.png" /></p> </blockquote> <p>四、切换用户命令</p> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p>su: switch user</p> <p><span style="line-height: 1.5"> su [OPTIONS] USERNAME </span></p> <p><span style="line-height: 24px"> </span>-l:完全切换 ,l可省略</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px">备注:如果不使用“-l”切换用户,只是切换了过去,但其实环境变量,家目录都没有改变。</p></blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p>-c 'COMMAND':仅以指定用户运行命令,并取回结果(一般用于脚本中)</p> </blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px">例子:su wqp -c 'ls' ————> fstab</p></blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px">表示并不切换账号而执行某个命令</p></blockquote> </blockquote> </blockquote> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p>实例截图:</p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /><img src="//cto.wang/usr/uploads/2016/07/20160703163717-11.png" title="1433987140119659.png" /></p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><p><img src="//cto.wang/usr/uploads/2016/07/20160703163716-24.gif" /></p> </blockquote> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"><blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"> <blockquote style="margin: 0px 0px 0px 40px;border: none;padding: 0px"></blockquote> </blockquote> </blockquote> </blockquote> <p>五、命令总结</p> <blockquote><p>(1)<span style="line-height: 1.5">用户和用户组相关的配置文件管理: <span style="line-height: 1.5">/etc/passwd , <span style="line-height: 1.5">/etc/group , <span style="line-height: 1.5">/etc/shadow ,<span style="line-height: 1.5">/etc/gshadow</span></span></span></span></span></p> </blockquote> <blockquote><p>(2)<span style="line-height: 1.5">用户账号管理相关命令 : useradd , groupadd , passwd , gpasswd , userdel , groupdel , usermod , groupmod , chsh , chfn , chage</span></p> </blockquote> <blockquote><p>(3)<span style="line-height: 1.5">查询用户信息相关命令: id , who,whoami,finger</span></p> </blockquote> <blockquote><p>(4)<span style="line-height: 1.5">切换用户命令: su</span></p> </blockquote> <p></p> <p></p> <p><span style="line-height: 1.5"><br /></span></p> <p></p> 最后修改:2021 年 12 月 10 日 10 : 53 AM © 允许规范转载 赞赏 如果觉得我的文章对你有用,请随意赞赏 赞赏作者 支付宝微信