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

📄 ch22_02.htm

📁 the unix power tools
💻 HTM
📖 第 1 页 / 共 2 页
字号:
></LI><LICLASS="listitem"><PCLASS="para">The information is not personal, yet no one should be able to modifythe information. Most of my directories are set up this way, with the permissionsof 755.</P></LI><LICLASS="listitem"><PCLASS="para">The files are managed by a team of people. This means group-write permission,or directories with the mode 775.</P></LI><LICLASS="listitem"><PCLASS="para">In the previous case, for confidential projects, you may want to denyaccess to people outside the group.In this case, make directories with mode 770.</P></LI></OL><PCLASS="para">You could just create a directory with the proper permissions,and put the files inside the directory, hoping the permissions of the directory will &quot;protect&quot;the files in the directory.This is not adequate. Suppose you had a directory with permissions755 and a file with permissions 666 inside the directory.Anyone could change the contents of this file because the world has search access on the directory andwrite access to the file.</P><PCLASS="para">What is needed is a mechanism to prevent any new file from having world-write access.This mechanism exists with the<ACLASS="indexterm"NAME="AUTOID-23848"></A><ACLASS="indexterm"NAME="AUTOID-23850"></A><SPANCLASS="link"><EMCLASS="emphasis">umask</EM> command (<ACLASS="linkend"HREF="ch22_04.htm"TITLE="Setting an Exact umask ">22.4</A>)</SPAN>.If you consider that a new directory would get permissions of 777, and that new files would get permissions of 666, the<EMCLASS="emphasis">umask</EM>command specifies permissions to &quot;take away&quot;from all new files.To &quot;subtract&quot;world-write permission from a file, 666 must have 002 &quot;subtracted&quot;from the default value to get 664.To subtract group and world write, 666 must have 022 removed to leave644 as the permissions of the file.These two values of<EMCLASS="emphasis">umask</EM>are so common that it is useful to have some<SPANCLASS="link">aliases (<ACLASS="linkend"HREF="ch10_02.htm"TITLE="Aliases for Common Commands ">10.2</A>)</SPAN>defined:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">&#13;alias open umask 002alias shut umask 022</PRE></BLOCKQUOTE></P><PCLASS="para">With these two values of <EMCLASS="emphasis">umask</EM>,new directories will have permissions of 775 or 755.Most people have a<EMCLASS="emphasis">umask</EM>value of one of these two values.</P><PCLASS="para">In a friendly work group, people tend to use the <EMCLASS="emphasis">umask</EM>of 002, which allows others in your group to make changes to your files.Someone who uses the mask of 022 will cause grief to others working on a project.Trying to compile a program is frustrating when someone else owns files that you must delete but can't. You can rename files if this is the case or ask the system administrator for help.</P><PCLASS="para">Members of a team who normally use a default umask of 022 should find a means to change the mask value when working on the project.(Or else risk flames from your fellow workers!)Besides the<EMCLASS="emphasis">open</EM>alias above, some people have an alias that changes directories andsets the mask to group-write permission:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">alias proj &quot;cd /usr/projects/proj;umask 002&quot;</PRE></BLOCKQUOTE></P><PCLASS="para">This isn't perfect, because people forget to use aliases.You could have a special <EMCLASS="emphasis">cd</EM> alias and a private shell file in eachproject directory that sets the <EMCLASS="emphasis">umask</EM> when you <EMCLASS="emphasis">cd</EM> there.Other people could have similar files in the project directorywith different names.Article<ACLASS="xref"HREF="ch14_14.htm"TITLE="Automatic Setup When You Enter/Exit a Directory ">14.14</A>shows how.</P><PCLASS="para">Still another method is to run <SPANCLASS="link"><EMCLASS="emphasis">find</EM> (<ACLASS="linkend"HREF="ch17_01.htm#UPT-ART-7410"TITLE="The find Command Is Great; The Problem Is Finding How to Use It">17.1</A>)</SPAN>three times a dayand search for files owned by you in the project directory thathave the wrong permission:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch06_03.htm"TITLE="6.3 Predefined Environment Variables ">$USER</A> <ACLASS="co"HREF="ch09_21.htm"TITLE="9.21 Handle Too-Long Command Lines with xargs ">xargs</A> <ACLASS="co"HREF="ch22_07.htm"TITLE="22.7 Using chmod to Change File Permission ">chmod</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>find /usr/projects -user $USER ! -perm -020 -print | \</B></CODE><CODECLASS="userinput"><B>xargs chmod g+w</B></CODE></PRE></TD></TR></TABLE></P><PCLASS="para">You can use the command<SPANCLASS="link"><EMCLASS="emphasis">crontab -e</EM> (<ACLASS="linkend"HREF="ch40_15.htm"TITLE="crontab Script Makes crontab Editing Easier/Safer ">40.15</A>, <ACLASS="linkend"HREF="ch40_12.htm"TITLE="Periodic Program Execution: The cron Facility ">40.12</A>)</SPAN>to define when to run this command.<ACLASS="indexterm"NAME="AUTOID-23889"></A><ACLASS="indexterm"NAME="AUTOID-23890"></A>[If your system doesn't have personal <EMCLASS="emphasis">crontab</EM>s, use a<SPANCLASS="link">self-restarting <EMCLASS="emphasis">at</EM> job (<ACLASS="linkend"HREF="ch40_08.htm"TITLE="Automatically Restarting at Jobs ">40.8</A>)</SPAN>.<EMCLASS="emphasis">-JP</EM>&nbsp;]</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="UPT-ART-417-SECT-1.2">22.2.2 Which Group is Which? </A></H3><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-23898"></A>Since group-write permission is so important in a team project, you might be wondering how the group of a new file is determined?The answer depends on several factors.Before I cover these, you should note that Berkeley and AT&amp;T-based systems would use different mechanisms to determine the default group.</P><PCLASS="para">Originally UNIX required you to specify a new groupwith the<EMCLASS="emphasis">newgrp</EM>command.If there was a password for this group in the<EMCLASS="emphasis">/etc/group</EM>file, and you were not listed as one of the members of the group,you had to type the password to change your group.</P><PCLASS="para">Berkeley-based versions of UNIX would use the current directory to determinethe group of the new file. That is, if the current directory has <EMCLASS="emphasis">cad</EM>as the group of the directory,any file created in that directory would be in the same group.To change the default group, just change to a different directory.</P><PCLASS="para">Both mechanisms had their good points and bad points.The Berkeley-based mechanismmade it convenient to change groups automatically.However, there is a fixed limit of groups one could belong to.SunOS 4 has a limit of 16 groups. Earlier versions had a limit of eight groups.</P><PCLASS="para">SunOS and System V Release 4 support both mechanisms.The entire disk can be mounted with eitherthe AT&amp;T or the Berkeley mechanism. If it is necessary to control thison a directory-by-directory basis, a<SPANCLASS="link">special bit (<ACLASS="linkend"HREF="ch22_05.htm"TITLE="Group Permissions in a Directory with the setgid Bit ">22.5</A>)</SPAN>in the file permissions is used.If a disk partition is mounted without the Berkeley group mechanism, then a directory with this special bit will make new files have the same groupas the directory.Without the special bit, the group of all new files depends on thecurrent group of the user.</P></DIV><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">BB</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch22_01.htm"TITLE="22.1 Introduction to File Ownership and Security "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 22.1 Introduction to File Ownership and Security "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch22_03.htm"TITLE="22.3 Who Will Own a New File? "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 22.3 Who Will Own a New File? "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">22.1 Introduction to File Ownership and Security </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">22.3 Who Will Own a New File? </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

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