📄 206-208.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Configuration and Installation:Basic Linux Tools</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=1558285660//-->
<!--TITLE=Linux Configuration and Installation//-->
<!--AUTHOR=Patrick Volkerding//-->
<!--AUTHOR=Kevin Reichard//-->
<!--AUTHOR=Eric Foster//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=4//-->
<!--PAGES=206-208//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="203-206.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="208-212.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading11"></A><FONT COLOR="#000077">File Permissions and Linux</FONT></H3>
<P>When you first use your Linux system and are not logged in as the root user, you might be in for some rude surprises when you try to write to a directory that’s not your own home directory. Essentially, Linux will tell you that you cannot write to the directory.
</P>
<P>Because UNIX is a creature centered around security, Linux allows <I>permissions</I> to be designated for files and directories. If you lack the proper permissions, you can’t change files or directories. The root user, of course, has the proper permissions to access every file in the Linux filesystem (which means that you shouldn’t expect absolute security if you’re working on a larger system). Under Linux, there are three different levels of permissions: <I>owner</I>, <I>group</I>, and <I>world</I>.</P>
<P>Permissions are an extremely frustrating part of Linux if you’re a new user. While there are permissions under DOS, they are not frequently used.</P>
<P>To find what permissions are applied to files, use the following command line:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/$ ls -l
-rwxrwxrwx 1 kevinr group1 512 Apr 3 19:12 test
-rwxrwxrwx 1 kevinr group1 512 Apr 3 19:27 test.bk
drwxrwxrwx 1 kevinr group1 2146 Apr 1 04:41 memos
-rwx------ 1 kevinr group1 854 Apr 2 19:12 data
</PRE>
<!-- END CODE SNIP //-->
<P>There’s actually a rhyme and reason to the mess of numbers and letters presented here, but it’s best explained going right to left in columns (and focusing on the first line of the listings):
</P>
<DL>
<DD><B>•</B> The eighth column (<B>test</B>) lists the filename.
<DD><B>•</B> The seventh column (<B>19:12</B>) lists the time the file was created.
<DD><B>•</B> The sixth column (<B>Apr 3</B>) lists the date the file was created.
<DD><B>•</B> The fifth column (<B>512</B>) lists the size of the file in bytes.
<DD><B>•</B> The fourth column (<B>group1</B>) lists the group the file belongs to. (We’ll explain this later.)
<DD><B>•</B> The third column (<B>kevinr</B>) lists the owner of the file.
<DD><B>•</B> The second column (<B>1</B>) shows the number of links to the file.
<DD><B>•</B> The first column (<B>-rwxrwxrwx</B>) lists the permissions associated with the file and the type of the file.
</DL>
<P>The leading hyphen (<B>-</B>) tells us that the file is an ordinary file, which was covered earlier in this section. When you do an <B>ls -l</B>, you’ll see various file-type listings, shown in Table 4.2.</P>
<CENTER>
<TABLE WIDTH="95%"><CAPTION><B>Table 4.2</B> File Types Listed with the ls -l Command Line
<TR>
<TH WIDTH="25%" ALIGN="LEFT">Listing
<TH WIDTH="75%" ALIGN="LEFT">File Type
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TD>-
<TD>Ordinary file.
<TR>
<TD>d
<TD>Directory.
<TR>
<TD>l
<TD>Link.
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
</CENTER>
<P>There are other file types listed with this command, but you won’t usually see them with Linux.
</P>
<P><FONT SIZE="+1"><B>Permission Lines</B></FONT></P>
<P>The remainder of the first column, covering specific permissions, commands most of our attention in this discussion. Basically, the permissions are broken down into three groups. Remember that permissions are applied to the owner of the file (in this case, <B>kevinr</B>), the group of the file (in this case, <B>group1</B>), and the world at large. Applying this trinity to a permission line of <B>rwxrwxrwx</B>, we can see that the owner has the ability to read the file (indicated by <I>r</I>), write the file (indicated by <I>w</I>), and execute the file (indicated by <I>x</I>). Moving on, the group has the ability to read the file (indicated by <I>r</I>), write the file (indicated by <I>w</I>), and execute the file (indicated by <I>x</I>). Finally, the world has the ability to read the file (indicated by <I>r</I>), write the file (indicated by <I>w</I>), and execute the file (indicated by <I>x</I>). In other words, this file is free game for anyone with access to your Linux filesystem.</P>
<P>Things are a little different with the following listing:</P>
<!-- CODE SNIP //-->
<PRE>
-rwx------ 1 kevinr group1 854 Apr 2 19:12 data
</PRE>
<!-- END CODE SNIP //-->
<P>When there are no letters indicating a permission—as in the case with the hyphen—the permissions are restricted. With this file, the owner has the ability to read the file (indicated by <I>r</I>), write the file (indicated by <I>w</I>), and execute the file (indicated by <I>w</I>). However, no one else has <I>any</I> permissions with this file.</P>
<P>With most of the Linux operating system, you’ll see a permission like <B>rwxr-xr-x</B>, with <B>root</B> being the owner of the file. In this instance, an average user (that is, someone not logged in as <B>root</B>) has the ability to execute files (an important capability to have) and read the files but lacks the ability to write (that is, change) the file. This protection exists for many reasons, but basically it exists to prevent users from wreaking unanticipated havoc.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>When you install and configure new software on your Linux system and want to install it in one of the standard file locations, you’ll need to login as <B>root</B>.<HR></FONT>
</BLOCKQUOTE>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="203-206.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="208-212.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 + -