How to assign a SSL Certificate to IIS7 Site from Command Prompt

前端 未结 7 988
执笔经年
执笔经年 2020-12-04 12:52

Can you advise me whether it is possible or not to assign a SSL Certificate to a website in IIS7 using the APPCMD application?

I am familiar with the command to set

相关标签:
7条回答
  • 2020-12-04 13:30

    Using PowerShell + netsh:

    $certificateName = 'example.com'
    $thumbprint = Get-ChildItem -path cert:\LocalMachine\My | where { $_.Subject.StartsWith("CN=$certificateName") } | Select-Object -Expand Thumbprint
    $guid = [guid]::NewGuid().ToString("B")
    netsh http add sslcert ipport="0.0.0.0:443" certhash=$thumbprint certstorename=MY appid="$guid"
    

    If you need a named binding, replace netsh call with this:

    netsh http add sslcert hostnameport="$certificateName:443" certhash=$thumbprint certstorename=MY appid="$guid"
    
    0 讨论(0)
  • 2020-12-04 13:34

    Using the answers from this post, I created a single script that did the trick for me. It starts from the pfx file, but you could skip that step.

    Here it is:

    cd C:\Windows\System32\inetsrv
    
    certutil -f -p "pa$$word" -importpfx "C:\temp\mycert.pfx"
    
    REM The thumbprint is gained by installing the certificate, going to cert manager > personal, clicking on it, then getting the Thumbprint.
    REM Be careful copying the thumbprint. It can add hidden characters, esp at the front.
    REM appid can be any valid guid
    netsh http add sslcert ipport=0.0.0.0:443 certhash=5de934dc39cme0234098234098dd111111111115 appid={75B2A5EC-5FD8-4B89-A29F-E5D038D5E289}
    
    REM bind to all ip's with no domain. There are plenty of examples with domain binding on the web
    appcmd set site "Default Web Site" /+bindings.[protocol='https',bindingInformation='*:443:']
    
    0 讨论(0)
  • 2020-12-04 13:36

    @David and @orip have it right.

    However, I did want to mention that the ipport parameter specified in the example (0.0.0.0:443) is what the MSDN calls the "unspecified address (IPv4: 0.0.0.0 or IPv6: [::])".

    I went looking it up, so I figured I'd document here to save someone else the time. This article focuses on SQL Server, but the information is still relevant:

    http://msdn.microsoft.com/en-us/library/ms186362.aspx

    0 讨论(0)
  • 2020-12-04 13:40

    With PowerShell and the WebAdministration module, you can do the following to assign an SSL certificate to an IIS site:

    # ensure you have the IIS module imported
    Import-Module WebAdministration
    
    cd IIS:\SslBindings
    Get-Item cert:\LocalMachine\My\7ABF581E134280162AFFFC81E62011787B3B19B5 | New-Item 0.0.0.0!443
    

    Things to note... the value, "7ABF581E134280162AFFFC81E62011787B3B19B5" is the thumbprint for the certificate you want to import. So it needs to be imported into the certificate store first. The New-Item cmdlet takes in the IP address (0.0.0.0 for all IPs) and the port.

    See http://learn.iis.net/page.aspx/491/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in/ for more details.

    I've tested this in Windows Server 2008 R2 as well as Windows Server 2012 pre-release.

    0 讨论(0)
  • 2020-12-04 13:46

    This helped me a lot: a simple guide, by Sukesh Ashok Kumar, to setting up SSL for IIS from the command line. Includes importing/generating the certificate with certutil / makecert.

    http://www.awesomeideas.net/post/How-to-configure-SSL-on-IIS7-under-Windows-2008-Server-Core.aspx

    EDIT: if the original URL is down, it's still available through the Wayback Machine.

    0 讨论(0)
  • 2020-12-04 13:50

    The answer is to use NETSH. For example

    netsh http add sslcert ipport=0.0.0.0:443 certhash='baf9926b466e8565217b5e6287c97973dcd54874' appid='{ab3c58f7-8316-42e3-bc6e-771d4ce4b201}'
    
    0 讨论(0)
提交回复
热议问题