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

📄 417-420.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=417-420//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

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

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

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

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading22"></A><FONT COLOR="#000077">Managing Groups with <I>gpasswd</I>

</FONT></H4>

<P>To add users to an existing group, log in as the root user and enter the following command:

</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# gpasswd -a <I>loginname groupname</I>

</PRE>

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

<P>where <TT><I>loginname</I></TT> is the login name of the user you want to add to the group <TT><I>groupname</I></TT>.</P>

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

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# gpasswd -a vector ittf

</PRE>

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

<P>To remove a user from an existing group, log in as the root user and enter the following command:

</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# gpasswd -d <I>loginname groupname</I>

</PRE>

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

<P>where <TT><I>loginname</I></TT> is the login that you want to remove from the group <TT><I>groupname</I></TT>.</P>

<P>For example, if you wanted to remove the user yoko from the group beatles, you would use the command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# gpasswd -d yoko beatles

</PRE>

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

<P>For a full list of command-line options available for the <TT>gpasswd</TT> command, see the related <TT>man</TT> page.</P>

<H4 ALIGN="LEFT"><A NAME="Heading23"></A><FONT COLOR="#000077">Using the <I>chgrp</I> Command

</FONT></H4>

<P>To change the group of a file, use the <TT>chgrp</TT> command. Log in as the root user and enter the following command:</P>

<!-- CODE SNIP //-->

<PRE>

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

</PRE>

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

<P>where <TT><I>groupname</I></TT> is the name of the group you want to change the file&#146;s group setting to, and <TT><I>filename</I></TT> is the name of the file for which you want the group changed.</P>

<P>For example, if you wanted to change the group for the file <TT>index.html</TT> to <TT>www</TT>, you would use <TT>chgrp</TT> as follows:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# <B>chgrp www index.html</B>

</PRE>

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

<P>To change the group of a directory and all its subdirectories and files, you can use the <TT>chgrp</TT> command with the <TT>-R option</TT>. For example, to change the group on all the files in the <TT>htdocs</TT> directory to <TT>www</TT>, you would use:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# <B>chgrp -R www htdocs</B>

</PRE>

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

<H3><A NAME="Heading24"></A><FONT COLOR="#000077">Changing File Ownership and Permissions</FONT></H3>

<P>Two programs in the command-line arsenal help change file ownership and permissions. <TT>chown</TT>, or Change Ownership, lets you change a file (or group of files) to another owner. <TT>chmod</TT> lets you change the access permissions to individual files.</P>

<H4 ALIGN="LEFT"><A NAME="Heading25"></A><FONT COLOR="#000077">Using the <I>chown</I> Command

</FONT></H4>

<P>To change the owner of a file, you use the <TT>chown</TT> command. Log in as the root user and enter the following command:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# chown <I>ownername filename</I>

</PRE>

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

<P>where <TT><I>ownername</I></TT> is the login name of the user you want to change the file&#146;s owner setting to, and <TT><I>filename</I></TT> is the name of the file for which you want the owner changed.</P>

<P>For example, if you wanted to change the owner for the file <TT>index.html</TT> to sshah, you would use <TT>chown</TT> as follows:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# chown sshah index.html

</PRE>

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

<P>To change the owner of a directory and all its subdirectories and files, you can use the <TT>chown</TT> command with the <TT>-R</TT> option. For example, to change the owner on all the files in the <TT>htdocs</TT> directory to sshah, you would use:</P>

<!-- CODE SNIP //-->

<PRE>

[root&#64;insoc /root]# chown -R sshah htdocs

</PRE>

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

<H4 ALIGN="LEFT"><A NAME="Heading26"></A><FONT COLOR="#000077">Using the <I>chmod</I> Command

</FONT></H4>

<P>Before we can explain the usage of the <TT>chmod</TT> command, you need to first understand file permissions.</P>

<P>In Linux, every file and directory has three sets of access permissions: those applied to the owner of the file, those applied to the group the file has, and those of all users in the system. You can see these permissions when you do an <TT>ls -lg</TT>. For example:</P>

<!-- CODE SNIP //-->

<PRE>

drwxr-xr-x   2 sshah    sysadmin     1024 Feb 14 15:49

wedding_plans

-rw-------   1 sshah    sysadmin     2465 Feb  5 19:22

index.html

</PRE>

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

<P>The first column of the listing is the permissions of the file. The first character represents the type of file (&#235;d&#146; means directory, &#235;l&#146; means symbolic link, and so on), and the next nine characters are the permissions. The first three characters represent the permissions held by the file&#146;s owner, the second three are for the group the file is in, and the last three represent the world permissions.

</P>

<P>The following letters are used to represent permissions:</P>

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

<TH WIDTH="50%" ALIGN="LEFT">Letter

<TH WIDTH="50%" ALIGN="LEFT">Meaning

<TR>

<TD>r

<TD>Read

<TR>

<TD>w

<TD>Write

<TR>

<TD>x

<TD>Execute

</TABLE>

<P>Each permission has a corresponding value. The read attribute is equal to 4, the write attribute is equal to 2, and the execute attribute is equal to 1. When you combine attributes, you add their values. See the following examples.

</P>

<P>The most common groups of three and their meanings are:</P>

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

<TH WIDTH="30%" ALIGN="LEFT">Permission

<TH WIDTH="30%" ALIGN="LEFT">Values

<TH WIDTH="40%" ALIGN="LEFT">Meaning

<TR>

<TD>---

<TD>0

<TD>No permissions

<TR>

<TD>r--

<TD>4

<TD>Read only

<TR>

<TD>rw-

<TD>6

<TD>Read and write

<TR>

<TD>rwx

<TD>7

<TD>Read, write, and execute

<TR>

<TD>r-x

<TD>5

<TD>Read and execute

<TR>

<TD>--x

<TD>1

<TD>Execute only

</TABLE>

<P>Although other combinations do exist (for example: -wx), they are nonsensical, and the likelihood you&#146;ll ever run across them is almost nil.

</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

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

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

<TD><A HREF="420-422.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 + -