rhl47.htm
来自「linux的初学电子书」· HTM 代码 · 共 1,210 行 · 第 1/3 页
HTM
1,210 行
<FONT COLOR="#000080">ftp stream tcp nowait root /usr/etc/ftpd ftpd -l</FONT></PRE>
<P>If the line doesn't exist, add it to the file. With most Linux systems, the line is already in the file, although it may be commented out. Remove the comment symbol if this is the case. The FTP entry essentially specifies to inetd that FTP is to use
TCP, and that it should spawn ftpd every time a new connection is made to the FTP port. In the preceding example, the ftpd daemon is started with the -l option, which enables logging. You can ignore this option if you want. You should replace the pathname
/usr/etc/ftpd with the location of your FTP daemon.
<BR>
<P>There are several ftpd daemon options that you can add to the /etc/inetd.config line to control ftpd's behavior. The following list contains the most commonly used options:
<BR>
<UL>
<LI>-d Adds debugging information to the syslog.
<BR>
<BR>
<LI>-l Activates a logging of sessions (only failed and successful logins, not debug information). If the -l option is specified twice, all commands are logged, too. If specified three times, the size of all get and put file transfers are added as well.
<BR>
<BR>
<LI>-t Sets the timeout period before ftpd terminates after a session is concluded (default is 15 minutes). The value is specified in seconds after the -t option.
<BR>
<BR>
<LI>-T Sets the maximum timeout period (in seconds) that a client can request. The default is two hours. This lets a client alter the normal default timeout for some reason.
<BR>
<BR>
<LI>-u Sets the umask value for files uploaded to the local system. The default umask is 022. Clients can request a different umask value.
<BR>
<BR>
</UL>
<BR>
<A NAME="E69E500"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>FTP Logins</B></FONT></CENTER></H4>
<BR>
<P>If you are going to set up a user-based FTP service where each person accessing your system has a valid login name and password, then you must create an account for each user in the /etc/passwd file. If you are not allowing anonymous FTP access, do not
create a generic login that anyone can use.
<BR>
<P>To set up an anonymous FTP server, you must create a login for the anonymous user ID (if one doesn't already exist; many versions of Linux have the entry already completed upon installation). This is done in the normal process of adding a user to the
/etc/passwd file. The login name is whatever you want people to use when they access your system, such as anonymous or ftp. You need to select a login directory for the anonymous users that can be protected from the rest of the file system. A typical
/etc/passwd entry looks like this:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">ftp:*:400:51:Anonymous FTP access:/usr/ftp:/bin/false</FONT></PRE>
<P>This sets up the anonymous user with a login of ftp. The asterisk password prevents anyone gaining access to the account. The user ID number (400) is, of course, unique to the entire system. For better security, it is a good idea to create a separate
group just for the anonymous FTP access (edit the /etc/group file to add a new group), then set the ftp user to that group. Only the anonymous FTP user should belong to that group because it can be used to set file permissions to restrict access and make
your system more secure. The login directory in the preceding example is /usr/ftp, although you could choose any directory as long as it belongs to root (for security reasons, again). The startup program shown in the preceding example is /bin/false, which
helps protect your system from access to accounts and utilities that do not have a strong password protection.
<BR>
<BR>
<A NAME="E69E501"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Setting Up the Directories</B></FONT></CENTER></H4>
<BR>
<P>As you will see in the next section, "Setting Permissions," you can try to make the entire anonymous FTP subdirectory structure a file system unto itself, with no allowance for the anonymous user to get anywhere other than /usr/ftp (or
whatever directory you use for anonymous access). For this reason, you need to create a mini-file system just for the anonymous FTP access which holds the usual directory names and basic files that anyone logging in will need.
<BR>
<P>The process for setting up the directories that your anonymous FTP login will need is simple, requiring you to create a number of directories and copy files into them. Here's the basic procedure:
<BR>
<OL>
<LI>Create the bin directory (/usr/ftp/bin, for example) and copy the directory listing command ls that users will need to view directory and file details.
<BR>
<BR>
<LI>Create the etc directory (usr/ftp/etc, for example) and copy your passwd file (/etc/passwd) and group file (/etc/group) into it. We'll edit these files in a moment.
<BR>
<BR>
<LI>Create the lib directory (/usr/ftp/lib, for example) and copy the files /lib/ld.so and /lib/libc.so.X (where X is the version number of the libc file) into it. These files are used by ls. Do this step only if your ls command requires these files; most
versions of Linux do not have this dependency.
<BR>
<BR>
<LI>Create the pub directory (/usr/ftp/pub, for example) to hold your accessible files. We'll look at this directory in more detail in a moment.
<BR>
<BR>
<LI>Create the dev directory (/usr/ftp/dev, for example) and use the mknod command to copy the /dev/zero file. You need to retain the same major and minor device numbers as the /dev/zero file in /dev. This device file is used by ld.so (and hence ls). Do
this step only if ls requires the /lib directory files mentioned earlier.
<BR>
<BR>
</OL>
<P>The copies of the /etc/passwd and /etc/group files are copied into the ~ftp/etc directory. You should edit these files to remove all passwords and replace them with an asterisk. Remove all entries in both /etc/passwd and /etc/group, except those used by
the anonymous FTP login (usually just anonymous and bin).
<BR>
<P>The ~ftp/pub directory structure can be used to store the files you want to allow anonymous users to access. Copy them into this directory. You can create subdirectories as you need them for organizational purposes. It may be useful to create an upload
directory somewhere in the ~ftp/pub directory structure which has write permission, so that users can upload files to you only into this upload area.
<BR>
<BR>
<A NAME="E69E502"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Setting Permissions</B></FONT></CENTER></H4>
<BR>
<P>You can use the chroot command to help protect your system. The chroot command makes the root directory appear to be something other than / on a file system. For example, since chroot is always set for the anonymous FTP login, any time anonymous users
type a cd command, it can always be relative to their home directory. In other words, when they type cd /bin they will really be changing to /usr/ftp/bin if the root has been set to /usr/ftp. This helps prevent access to any other areas of the file system
than the FTP directory structure.
<BR>
<P>If you do create an upload area, you may want to set the permissions to allow execute and write, but not read (to prevent another user downloading the files someone else has uploaded).
<BR>
<P>Set all permissions for directories under ~ftp/ to prevent write access by user, group, or other. Make sure the directories and files under ~ftp are set to allow the anonymous login to read them (set their ownership and group permissions to the root
login and group ID), and set only read permission. The directories will need execute and read permission to enable the anonymous users to enter them and obtain directory listings. This provides pretty good security. All directories in the ~ftp directory
structure should have the permissions set with the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">chmod 555 dir_name</FONT></PRE>
<P>which sets read-execute permission only. The exception is the upload directory, which can have write permission as noted earlier.
<BR>
<BR>
<A NAME="E69E503"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Test the System</B></FONT></CENTER></H4>
<BR>
<P>Before you let anyone else onto your Linux FTP system, log into it yourself and try to access files you shouldn't be able to access, move into directories out of the ~ftp structure, and write files where you shouldn't be able to. This will provide a
useful test of the permissions and directory structure. Spend a few minutes trying to read and write files. Make sure your system is buttoned up: If you don't, someone else will find the holes and exploit them.
<BR>
<P>It is a useful idea to set up a mailbox for the FTP administrator so users on other systems who need help or information can send mail to you. Create a mail alias such as ftp-admin in the file /etc/aliases (and run newaliases to make it effective).
<BR>
<P>Since this is a system administration book, we won't go into much detail about how to organize your directory structure, but a few useful tips may help you. To begin, decide what you want to store in your FTP directories and organize the structure
logically. For example, if you are making available programs you have written, set up separate directories for each. A README file in each directory will help show browsers what it contains. A master README or INSTRUCTIONS file in the ~ftp directory can
help explain how your site is set up and what its contents are.
<BR>
<BR>
<A NAME="E68E378"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>A More Secure FTP</B></FONT></CENTER></H3>
<BR>
<P>The FTP system discussed in the preceding sections, which is the basic one supplied with practically every Linux distribution, requires a bit of work to make it secure. However, it is still vulnerable to very experienced crackers. There's a better
alternative if you are paranoid about your system's security: WU FTP. Developed at Washington University, WU FTP adds some extra features to the standard FTP system:
<BR>
<UL>
<LI>Better control of user and group IDs
<BR>
<BR>
<LI>Better tracking of uploads and downloads
<BR>
<BR>
<LI>Automatic shutdown
<BR>
<BR>
<LI>Automatic compression and decompression of files
<BR>
<BR>
</UL>
<P>If these features sound useful, you can obtain a copy of the source code of WU FTP from several sites, although the primary site is wuarchive.wustl.edu. Check for the file /packages/wuarchive-ftpd/wu-ftpd-2.4.tar.Z. You will get the source code which
needs to be compiled on your Linux system.
<BR>
<P>WU FTP uses a number of environment variables to control the service, and the accompanying documentation helps you set it up properly. Setting up WU FTP is much more complex than standard FTP, and the extra security, while useful, may be unnecessary for
many FTP site machines that you may set up at home or work (unless you have sensitive information).
<BR>
<BR>
<A NAME="E68E379"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>
<BR>
<P>The information in this chapter enables you to set up your system as a full anonymous FTP site or just a site for the users you want to gain access. Although the process is simple, you have to take care to ensure the file permissions are properly set.
Once your FTP site is up, you can let others on the Internet or your local area network know that you are running, as well as the type of material you store on your system. Then sit back and share!
<BR>
<BR>
<A NAME="E69E504"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Checklist Protecting an Anonymous FTP System</B></FONT></CENTER></H4>
<BR>
<P>Anonymous FTP is fast, relatively easy to use, and a huge security problem if you don't carefully set up your system. The following list summarizes a few simple steps to setting up a better anonymous FTP site:
<BR>
<OL>
<LI>Create a user account called ftp. Edit the /etc/passwd file manually and replace the password with an asterisk in the second field. This prevents anyone from gaining access through the ftp account.
<BR>
<BR>
<LI><A NAME="I2"></A>If a home directory wasn't created for the ftp user when you created the account, set up a home directory for the ftp user's sole use (such as /home/ftp).
<BR>
<BR>
<LI>Set the ftp home directory so that the root user is the owner:
<BR>chown root /usr/ftp
<BR>
<LI>Make the ftp home directory unwritable to anyone with the command:
<BR>chmod ugo-w /usr/ftp
<BR>
<LI>Create a bin directory under the ftp home directory:
<BR>mkdir ~ftp/bin
<BR>
<LI>Make the ~ftp/bin directory owned by root and unwritable to anyone else:
<BR>chown root ~ftp/bin
<BR>chmod ugo-w ~ftp/bin
<BR>
<LI>Place a copy of the listing commands (and any others that you want anonymous FTP users to use) in the bin directory:
<BR>cp /bin/ls ~ftp/bin
<BR>
<LI>Create an etc directory under the ftp home directory and make it owned by root and unwritable:
<BR>mkdir ~ftp/etc
<BR>chown root ~ftp/etc
<BR>chmod ugo-w ~ftp/etc
<BR>
<LI>Copy the /etc/passwd and /etc/group files into the ~ftp/etc directory. Edit both files to remove all user accounts except ftp (and ftp's group). (At the very least, remove all passwords for other accounts by placing asterisks in the password field.)
<BR>
<BR>
<LI>Create the directory ~ftp/pub/incoming, and make it owned by root. Then, make the directory writable by anyone:
<BR>mkdir ~ftp/pub/incoming
<BR>chown root ~ftp/pub/incoming
<BR>chmod ugo+w ~ftp/pub/incoming
<BR>
<LI>Place any files you want accessible by anonymous FTP into the ~ftp/pub directory. Users logging in through anonymous FTP will be able to transfer the files out. Allowing users to write files into the directory may not be desirable, so change the
permissions or check the files frequently.
<BR>
<BR>
</OL>
<P>By following these steps (modified for your own particular needs), you can create a secure site that lets you breathe a little easier.
<P ALIGN=LEFT>
<A HREF="rhl46.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl46.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="#I0" TARGET="_self"><IMG SRC="purtop.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></A>
<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="rhl48.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl48.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
</BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?