⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 414-417.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Using Linux:Managing Users and Groups</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0789716232//-->

<!--TITLE=Using Linux//-->

<!--AUTHOR=William Ball//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=25//-->

<!--PAGES=414-417//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="411-414.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="417-420.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading15"></A><FONT COLOR="#000077">Modifying Users with the <I>usermod</I> Command

</FONT></H4>

<P>The <TT>usermod</TT> command allows you to change all the parameters you set for a user when adding him or her to the system. Note that the user cannot be logged in when you are changing his or her login, UID, GID, or home directory because the system will get very confused.</P>

<P>To change a user&#146;s configuration information, log in as the root user and enter the following command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc]# usermod -c &#147;New <TT>Name</TT>&#148; -d homedir -m -g

groupname -s shell -l newlogin currentlogin

</PRE>

<!-- END CODE SNIP //-->

<P>where <TT><I>New Name</I></TT> is the user&#146;s new real name (for example, if a user named Kurt Valaquen wanted to change his name to Kurt Harland), <TT><I>homedir</I></TT> is the new home directory for the user, <TT><I>groupname</I></TT> is the name of the default user group he will belong to, <TT><I>shell</I></TT> is the desired shell of the user, <TT><I>newlogin</I></TT> is the new login name the user wants, and finally <TT><I>currentlogin</I></TT> is the login name of the user you want to change.</P>

<P>For example, if a user wants to set his name to &#147;Kurt Harland&#148; with a home directory of <TT>/home/vector</TT>, a default group setting to <TT>ittf</TT>, using the shell <TT>/bin/bash</TT> and using the login name vector, you would use the following command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# usermod --o &#147;Kurt Harland&#148; --d /home/

vector --m --q ittf --s /bin/bash --l vector vector

</PRE>

<!-- END CODE SNIP //-->

<P>See the <TT>man</TT> page regarding <TT>usermod</TT> for a list of all the available command-line options.</P>



<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">

<TR><TD><FONT SIZE="+1"><B>What am I typing?</B></FONT>

<BR>If the preceding command appears cryptic to you, don&#146;t worry. Its design was geared toward functionality over readability. Let&#146;s dissect the preceding command to see what it is doing.

<P>The <TT><B>usermod</B></TT> portion simply specifies the command we are running. This program will interpret the remainder of the line.</P>

<P>The first thing that will be interpreted is the string <TT><B>-o &#148;Kurt Harland&#147;</B></TT>. The <TT><B>-o</B></TT> tells the program that we want to change the comment field of the password entry to &#148;Kurt Harland&#147;. Quotation marks are placed around his name so that the program doesn&#146;t get confused and think the string <TT>&#147;<B>Harland</B>&#148;</TT> is the next parameter.</P>

<P>Each of the parameters works in a similar way where strings that start with a dash character tell <TT><B>usermod</B></TT> that we want to change an aspect of the user&#146;s settings and the string that immediately follows is the desired value. The last parameter is the user&#146;s login, which is required for this command.</TABLE>



</P>

<H4 ALIGN="LEFT"><A NAME="Heading16"></A><FONT COLOR="#000077">Deleting Users with the <I>userdel</I> Command

</FONT></H4>

<P>To remove a user from your system, use the <TT>userdel</TT> command. Note that the user must be logged out of the system before removing him. To use <TT>userdel</TT>, log in as the root user and enter the following command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# <B>userdel --r <I>login</I></B>

</PRE>

<!-- END CODE SNIP //-->

<P>where <TT><I>login</I></TT> is the login name of the user you want to remove.</P>

<P>For example, if you want to remove the user <TT>vector</TT>, you would use <TT>userdel</TT> as follows:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# <B>userdel --r vector</B>

</PRE>

<!-- END CODE SNIP //-->

<P>See the <TT>man</TT> page for <TT>userdel</TT> of a list of all the command-line options.</P>

<H3><A NAME="Heading17"></A><FONT COLOR="#000077">Adding, Editing, and Deleting Groups</FONT></H3>

<P>Similar to the user commands, there are commands for controlling groups as well. They are

</P>

<TABLE WIDTH="80%"><TR>

<TD WIDTH="30%"><TT>groupadd</TT>

<TD WIDTH="70%">Add groups

<TR>

<TD><TT>groupmod</TT>

<TD>Modify groups

<TR>

<TD><TT>groupdel</TT>

<TD>Delete groups

</TABLE>

<H4 ALIGN="LEFT"><A NAME="Heading18"></A><FONT COLOR="#000077">Adding Groups with the <I>groupadd</I> Command

</FONT></H4>

<P>The <TT><I>groupadd</I></TT> command allows you to add groups to the system from the command line. To do so, log in as the root user and enter the following command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# <B>groupadd <I>groupname</I></B>

</PRE>

<!-- END CODE SNIP //-->

<P>where <TT>groupname</TT> is the name of the group you want to add to the system.</P>

<P>For example, to add the group <TT>www</TT> to your system, you would use the command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# <B>groupadd www</B>

</PRE>

<!-- END CODE SNIP //-->

<P>See the <TT>man</TT> page regarding <TT>groupadd</TT> for a full list of all the command-line options available.</P>

<H4 ALIGN="LEFT"><A NAME="Heading19"></A><FONT COLOR="#000077">Modifying Groups with the <I>groupmod</I> Command

</FONT></H4>

<P>To modify the name of a group after it has been created, use the <TT>groupmod</TT> command. To make the change, log in as the root user and enter the following command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# groupmod --n <I>newgroup currentgroup</I>

</PRE>

<!-- END CODE SNIP //-->

<P>where <TT><I>newgroup</I></TT> is the new name you want to give the group, and <TT><I>currentgroup</I></TT> is the current name of the group.</P>

<P>For example, to change a group name from admin to sysadmin, you would use the following command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# groupmod --n sysadmin admin

</PRE>

<!-- END CODE SNIP //-->

<P>See the <TT>man</TT> page regarding <TT>groupmod</TT> for a full list of all the command-line options available.</P>

<H4 ALIGN="LEFT"><A NAME="Heading20"></A><FONT COLOR="#000077">Deleting Groups with the <I>groupdel</I> Command

</FONT></H4>

<P>To remove an existing group, use the <TT>groupdel</TT> command as described here. Log in as the root user and enter the following command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# groupdel <I>groupname</I>

</PRE>

<!-- END CODE SNIP //-->

<P>where <TT>groupname</TT> is the group you want to delete. There is one catch, however. You cannot delete a group if it is the primary group of any users. You either need to remove the users or change their primary group using the <TT>usermod</TT> command first.</P>

<P>For example, to remove the group ittf, you would use the command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# <B>groupdel ittf</B>

</PRE>

<!-- END CODE SNIP //-->

<H3><A NAME="Heading21"></A><FONT COLOR="#000077">Changing User and Group Ownership</FONT></H3>

<P>Linux provides two programs to help you manage user and group ownership from the command line. The first, <TT>gpasswd</TT>, allows you to administer a group with relative ease. <TT>chgrp</TT>, the second program, allows users to change the group of particular files.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="411-414.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="417-420.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -