Search code examples
powershellcertificatekeystoreself-signedpfx

Self-signed certificates limited to a host?


I am generating self-signed .pfx certificates for a java application running on a couple of Windows servers. These certificates will be imported into their respective java keystores.

My question is: Can I generate a self-signed certificates for server2, server3 and server4 on server1? Is there anything in a certificate, apart from the dns name, that would bind it to the machine on which it was generated?

My concern is that if I generate the certificate for server2 on server1, the certificate will still be somehow bound to server 1 only.

I am using the following powershell script to generate the certificates:

$cert = New-SelfSignedCertificate -keyfriendlyname server1 -certstorelocation cert:\localmachine\my -dnsname server1.mydomain.com
Export-PfxCertificate -cert ‘cert:\localMachine\my\’ -FilePath C:\Certificates\server1.pfx -Password dummypassword

My idea was to simplify the process of generating the certificates by running the script on a single server and just altering the dnsname, alias and file name for each certificate.


Solution

  • You can generate a certificate on any machine for any machine, just set the common name correctly (certificate's CN field).

    See parameter -Subject of the PowerShell command

    Note that moving private keys around is a bad practice, you should instead generate the key-pair on the same machine that it is to be used by.