Thursday, June 28, 2012

How to request a certificate from windows server through the command line

To use the Certreq.exe utility to create and submit a certificate request, follow these steps:
Create an .inf file that specifies the settings for the certificate request. You can use the following sample code to create an .inf file.


Signature=”$Windows NT$

Subject = “” ; must be the FQDN of domain controller
EncipherOnly = FALSE
Exportable = FALSE ; TRUE = Private key is exportable
KeyLength = 1024   ; Common key sizes: 512, 1024, 2048,
  ;  4096, 8192, 16384
KeySpec = 1         ; Key Exchange
KeyUsage = 0xA0   ; Digital Signature, Key Encipherment
MachineKeySet = True
ProviderName = “Microsoft RSA SChannel Cryptographic Provider”
ProviderType = 12
RequestType = CMC

; Omit entire section if CA is an enterprise CA
OID= ; Server Authentication

CertificateTemplate = WebServer ;Omit line if CA is a stand-alone CA


Save the file as Request.inf.
Open a command prompt.
At the command prompt, type the following command, and then press ENTER:
certreq -new request.inf certnew.req
This command uses the information in the Request.inf file to create a request in the format that is specified by the RequestType value in the .inf file. When the request is created, the public and private key pair is automatically generated and then put in a request object in the enrollment requests store on the local computer.
At the command prompt, type the following command, and then press ENTER:
certreq -submit certnew.req certnew.cer
This command submits the certificate request to the CA. If there is more than one CA in the environment, the -config switch can be used in the command line to direct the request to a specific CA. If you do not use the -config switch, you will be prompted to select the CA to which the request should be submitted.

The -config switch uses the following format to refer to a specific CA:
computername\Certification Authority Name
For example, assume that the CA name is Corporate Policy CA1 and that the domain name is To use the certreq command together with the –config switch to specify this CA, type the following command:
certreq -submit -config “\Corporate Policy CA1” certnew.req certnew.cer
If this CA is an enterprise CA and if the user who submits the certificate request has Read and Enroll permissions for the template, the request is submitted. The issued certificate is saved in the Certnew.cer file. If the CA is a stand-alone CA, the certificate request will be in a pending state until it is approved by the CA administrator. The output from the certreq -submit command contains the Request ID number of the submitted request. As soon as the certificate has been approved, it can be retrieved by using the Request ID number.
Use the Request ID number to retrieve the certificate. To do this, type the following command, and then press ENTER:
certreq -retrieve RequestID certnew.cer
You can also use the -config switch here to retrieve the certificate request from a specific CA. If the -config switch is not used, you are prompted to select the CA from which to retrieve the certificate.
At the command prompt, type the following command, and then press ENTER:
certreq -accept certnew.cer
After you retrieve the certificate, you must install it. This command imports the certificate into the appropriate store and then links the certificate to the private key that is created in step 4.

Posted by admin in
Page 1 of 1 pages