Article Title: security settings for FTP servers in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Anonymous FTP is a frequently used service on the Internet. It is often used for Software Download websites and software exchange websites. To improve the security of anonymous FTP services, we will discuss this issue.
The following settings are composed of the experience and suggestions accumulated by many websites in the past. We believe that some
The desired website has different settings.
Set anonymous FTP
A. FTP daemon
The website must be sure to use the latest FTP daemon version.
B. Set the anonymous FTP directory
Root directory of anonymous ftp (~ And its sub-directory owner cannot be an ftp account, or an account in the same group as ftp. This is
Common setup problems. If these directories are owned by ftp accounts or accounts in the same group as ftp, and do not provide write protection, intruders may add files (for example :. Rhosts? N) or modify other files. Many websites? Shizuoka? Oot account. Set the root directory and sub-directory owner of anonymous FTP to root and the group to system ?? Why are there too many other users? Such as chmod 0755), so only root has the write power, which can help you maintain the FTP service's security ???
The following is an example of setting an anonymous ftp directory:
Drwxr-xr-x 7 root system 512 Mar 1 ./
Drwxr-xr-x 25 root system 512 Jan 4 ...... /
Drwxr-xr-x 2 root system 512 Dec 20 bin/
Drwxr-xr-x 2 root system 512 Mar 12 etc/
Drwxr-xr-x 10 root system 512 Jun 5 pub/
All files and link libraries, especially those used by FTP daemon and ~ Ftp/bin and ~ Files in ftp/etc should be protected in the same way as directories in the preceding example. These files and linked libraries must not be owned by ftp accounts or accounts in the same group as ftp, but must also be prevented from being written.
C. How can I use the cooperation partner to raise funds? We strongly recommend that the website do not use/etc/passwd in the system ~ The password file in the ftp/etc directory or/etc/group in the system ~ Group files in the ftp/etc directory. In ~ Put these files in the ftp/etc directory so that intruders can obtain them. These files are customizable and not used for access control.
We recommend that you ~ Ftp/etc/passwd and ~ Ftp/etc/group uses a replacement file. These files must be owned by the root user. The DIR command uses this file to display the owner and group names of the file and directory. The website must be determined ~ The/ftp/etc/passwd file does not contain any account names that are the same as those in the/etc/passwd file in the system. These files should only contain the owner and group names of files and directories in the FTP-class architecture to be displayed. In addition, confirm that the password field is "sorted. For example, use "*" to replace the password field.
Example of anonymous ftp password file in cert
Ssphwg: *: 3144: 20: Site Specific Policy Handbook Working Group ::
Cops: *: 3271: 20: COPS Distribution ::
Cert: *: 9920: 20: CERT ::
Tools: *: 9921: 20: CERT Tools ::
Ftp: *: 9922: 90: Anonymous FTP ::
Nist: *: 9923: 90: NIST Files ::
Example of anonymous ftp group files in cert
Cert: *: 20:
Ftp: *: 90:
II. Provide writable directories on your anonymous ftp
There is a risk that an anonymous ftp service allows users to store files. We strongly recommend that the website do not automatically create an upload directory unless related risks have been taken into account. The CERT/CC incident returned many events that resulted in illegal transfer of copyright software or account and password information using the upload directory. Denialof service is also reported maliciously by filling system files.
This section describes how to solve this problem using three methods. The first method is to use a corrected FTP daemon. The second method is to provide write restrictions on specific directories. The third method is to use an independent directory.
A. Modified FTP daemon
If your website plans to provide directories for file upload, we recommend that you use the modified FTP daemon to control the access to the file upload directories. This is the best way to avoid unnecessary write areas. The following are some suggestions:
1. Restrict that the uploaded files cannot be accessed again, so that they can be detected by the system administrator and placed in the appropriate location for users to download.
2. restrict the size of each online uploaded data.
3. limit the total amount of data transmitted according to the size of the existing disk.
4. Add logon records to detect improper use in advance.
If you want to modify the FTP daemon, you can obtain the program code from the vendor, or you can obtain the public FTP original code from the following places: wuarchive.wustl.edu ~ Ftp/packages/wuarchive-ftpd
Ftp.u.net ~ Ftp/systems/unix/bsd-sources/libexec/ftpd
Gatekeeper.dec.com ~ Ftp/pub/DEC/gwtools/ftpd.tar. Z
CERT/CC does not officially inspect, evaluate, or endorse the aforementioned FTP daemon. The FTP daemon to be used is determined by each user or organization, and CERT/CC recommends that each agency make a thorough assessment before installing and using these programs.
B. Use Protected Directories
If you want to provide the upload service on your FTP site, and you cannot modify the FTP daemon, we can use a complicated directory architecture to control access. This method needs to be planned in advance and cannot be used to prevent improper use of FTP-writable areas. However, many FTP sites still use this method.
To protect the upper-layer directories (~ Ftp/incoming), we only grant anonymous users permission to access the directory (chmod 751 ~ Ftp/incoming ). This action allows the user to change the directory location (cd), but does not allow the user to view the directory content. Ex:
Drwxr-x -- x 4 root system 512 Jun 11 incoming/
In ~ Ftp/incoming uses some directory names for only the persons you allow to upload them. To make it difficult for others to guess the directory name, we can use the password setting rule to set the directory name. Please do not use the directory name example in this article (to avoid your directory name being discovered by interested people and uploading files)
Drwxr-x-wx 10 root system 512 Jun 11 jajwu22/
Drwxr-x-wx 10 root system 512 Jun 11 :54 MhaLL-iF/
It is very important that once the directory name is intentionally or unintentionally leaked, this method has no protection effect. As long as the directory name is known to most people, it will not be able to protect the areas to be used. If the directory name is known to everyone, you have to delete or change those directories.
C. Use only one hard disk:
If you want to provide the upload service on your FTP site, and you cannot modify the FTP daemon, you can concentrate all the uploaded data on the same mount ~ File System on ftp/incoming. If yes, mount a separate hard disk ~ Ftp/incoming. The system manager should continuously check this directory (~ Ftp/incoming), so that you can know whether there is a problem with the open upload directory.
Restrict FTP User Directories
Anonymous FTP can effectively restrict user activity within the specified directory, but official FTP users are not subject to this restriction by default, it can read files that can be read by other users in the root directory, system directory, and other user directories.
How can I restrict specified users to their own directories like anonymous users? The following describes how to use red hat and wu-ftp.
1. Create a group and use the groupadd command. Generally, you can use an ftp group or any group name.
----- Related command: groupadd ftpuser
----- Related file:/etc/group
----- Help: man groupadd
2. Create a user, such as testuser. Create a user and run the adduser command. If you have created a user named testuser, you can directly edit the/etc/passwd file and add the user to the ftpuser group.
----- Related command: adduser testuser-g ftpuser
----- Related file:/etc/passwd
----- Help: man adduser
3. Modify the/etc/ftpaccess file and add it to the guestgroup definition: guestgroup ftpuser. This is the last 5 rows added.
Compress yes all
Tar yes all
Chmod no anonymous
Delete no anonymous
Overwrite no anonymous
Rename no anonymous
Chmod yes guest
Delete yes guest
Overwrite yes guest
Rename yes guest
Guestgroup ftpuser
In addition to adding the guestgroup ftpuser line, the other four lines also need to be added. Otherwise, after the user logs in, although the user can not return to the upper-level directory, the user can only upload, not overwrite, and delete files!
----- Related command: vi/etc/ftpaccess
----- Related file:/etc/ftpaccess
----- Help: man ftpaccess, man chroot
4. Copy the necessary files to the root directory of the user, copy the directory that comes with the ftp server, and put the bin under/home/ftp, the lib two directories are copied to the root directory of the user. Some commands (mainly ls) need to be supported by Lib; otherwise, the directory and file cannot be listed.
----- Related commands:
Cp-rf/home/ftp/lib/home/testuser; cp-rf/home/ftp/bin/home/testuser
5. In addition, do not forget to disable the user's telnet permission. Otherwise, it will be done in vain. Why not let the user telnet? Simple: Add a/dev/null Line to/etc/shells, then you can directly edit the/etc/passwd file and set your shell to/dev/null.
----- Related commands: vi/etc/passwd
This step can be done first when you create a user in step 2.
----- Related command: adduser testuser-g ftpuser-s/dev/null
Small experience: as long as the bin and lib directories under/home/ftp are cp to the/etc/skel directory, the bin and lib directories will be automatically CP to the user directory after the new user is created, you can also add the public_html directory and cgi-bin directory.
After the preceding settings, all FTP operations of the user testuser are restricted to the/home/testuser directory.