系统 FTP 身份验证 <authentication>

概述

<authentication> 用于配置可访问服务器上的站点的用户帐户。 结合使用身份验证和授权来保护对服务器上的内容的访问。 身份验证会确认用户的标识,而授权确定哪些资源用户可以访问或无法访问。

IIS 定义一种类型的身份验证规则“拒绝规则”。 使用拒绝规则可以定义哪些用户帐户或用户组无法访问服务器上的站点。

兼容性

版本 说明
IIS 10.0 <authentication> 元素在 IIS 10.0 中未进行修改。
IIS 8.5 <authentication> 元素在 IIS 8.5 中未进行修改。
IIS 8.0 <authentication> 元素是在 IIS 8.0 中引入的。
IIS 7.5 空值
IIS 7.0 空值
IIS 6.0 空值

安装

若要支持在 FTP 服务器上通过身份验证拒绝访问,必须安装 FTP 服务角色服务。

Windows Server 2012

  1. 按 Windows 徽标键,然后单击“服务器管理器”。

  2. 在“服务器管理器”中,单击“管理”,然后单击“添加角色和功能”

  3. 在“添加角色和功能”向导中

    • 开始之前页面上,单击下一步
    • 在“安装类型”页上,选择安装类型,然后单击“下一步”
    • 在“服务器选择”页上,选择适当的服务器,然后单击“下一步”
    • 在“服务器角色”页上,确保选中“Web 服务器(IIS)”,然后将其展开
    • 展开“FTP 服务器”,然后选择“FTP 服务”和“FTP 扩展性”,然后单击“下一步”
    • 在“功能”页上,单击“下一步”。
    • “确认安装选择”页中,单击“安装”
    • 在“结果” 页面中单击“关闭”

Windows 8

  1. 打开 Windows“控制面板”。
  2. 在 Windows 控制面板中,打开“程序和功能”
  3. 在“程序和功能”中,单击“打开或关闭 Windows 功能”
  4. 在“Windows 功能”对话框中,展开“Internet Information Services”,然后展开“FTP 服务器”
  5. 在“FTP 服务器”下面,选择“FTP 服务”和“FTP 扩展性”,然后单击“确定”。

操作方式

如何基于登录失败率拒绝对 FTP 服务器的访问

  1. 打开 Internet Information Services (IIS) 管理器:

    • 如果使用 Windows Server 2012 或更高版本:

      • 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”
    • 如果使用的是 Windows 8 或更高版本:

      • 按住 Windows 键,按字母 X,然后单击“控制面板”。
      • 单击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
  2. 在“连接”窗格中,选择服务器

  3. 在“主页”窗格中,双击“FTP 登录尝试限制”功能。

    Image of Home pane displaying Enable F T P Log on Attempt Restrictions feature selected.

  4. 在“FTP 登录尝试限制”对话框中,单击“启用”以启用限制,然后输入最大失败次数,还要输入在到达最大失败次数后,提示拒绝对 FTP 服务的访问的时间段。

  5. 单击“仅写入日志”将记录已满足的条件,但不阻止登录尝试。

  6. 在“操作”窗格中,单击“应用”

配置

<authentication> 元素在服务器级别配置。

特性

无。

子元素

元素 说明
denyByFailure 可选元素。

将 FTP 服务配置为基于失败率拒绝访问。

配置示例

以下示例配置 <denyByFailure> 元素。

<system.ftpServer>
   <security>
      <authentication>
         <denyByFailure enabled="true" maxFailure="5" entryExpiration="00:00:45" loggingOnlyMode="false" />
      </authentication>
   </security>
</system.ftpServer>

代码示例

以下代码示例根据登录失败率配置 FTP 服务器拒绝访问。

AppCmd.exe

appcmd.exe set config  -section:system.ftpServer/security/authentication /denyByFailure.enabled:"True" /denyByFailure.maxFailure:"10" /denyByFailure.entryExpiration:"00:00:35" /denyByFailure.loggingOnlyMode:"False"  /commit:apphost

注意

使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 apphost。 这会将配置设置提交到 ApplicationHost.config 文件中的相应位置部分。

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample {

    private static void Main() {
        
        using(ServerManager serverManager = new ServerManager()) { 
            Configuration config = serverManager.GetApplicationHostConfiguration();
            
            ConfigurationSection authenticationSection = config.GetSection("system.ftpServer/security/authentication");
            
            ConfigurationElement denyByFailureElement = authenticationSection.GetChildElement("denyByFailure");
            denyByFailureElement["enabled"] = true;
            denyByFailureElement["maxFailure"] = 10;
            denyByFailureElement["entryExpiration"] = TimeSpan.Parse("00:00:35");
            denyByFailureElement["loggingOnlyMode"] = false;
            
            serverManager.CommitChanges();
        }
    }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim authenticationSection As ConfigurationSection = config.GetSection ("system.ftpServer/security/authentication")
      Dim denyByFailureElement As ConfigurationElement = authenticationSection.GetChildElement("denyByFailure")
      denyByFailureElement("enabled") = true
      denyByFailureElement("maxFailure") = 10
      denyByFailureElement("entryExpiration") = TimeSpan.Parse("00:00:35")
      denyByFailureElement("loggingOnlyMode") = false
      serverManager.CommitChanges
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var authenticationSection = adminManager.GetAdminSection("system.ftpServer/security/authentication", "MACHINE/WEBROOT/APPHOST");
var denyByFailureElement = authenticationSection.ChildElements.Item("denyByFailure");
denyByFailureElement.Properties.Item("enabled").Value = true;
denyByFailureElement.Properties.Item("maxFailure").Value = 10;
denyByFailureElement.Properties.Item("entryExpiration").Value = "00:00:35";
denyByFailureElement.Properties.Item("loggingOnlyMode").Value = false;

adminManager.CommitChanges();

VBScript

Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set authenticationSection = adminManager.GetAdminSection("system.ftpServer/security/authentication", "MACHINE/WEBROOT/APPHOST")
Set denyByFailureElement = authenticationSection.ChildElements.Item("denyByFailure")
denyByFailureElement.Properties.Item("enabled").Value = true
denyByFailureElement.Properties.Item("maxFailure").Value = 10
denyByFailureElement.Properties.Item("entryExpiration").Value = "00:00:35"
denyByFailureElement.Properties.Item("loggingOnlyMode").Value = false

adminManager.CommitChanges()

PowerShell

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.ftpServer/security/authentication/denyByFailure" -name "enabled" -value "True"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.ftpServer/security/authentication/denyByFailure" -name "maxFailure" -value 10
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.ftpServer/security/authentication/denyByFailure" -name "entryExpiration" -value "00:00:35"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.ftpServer/security/authentication/denyByFailure" -name "loggingOnlyMode" -value "False"