Prerequisites
- An SSH Connection with access to the target server, or an LDAP Connection to the domain the server is joined to. See using an LDAP connection for many servers.
- For an LDAP Connection: the connection URL must use LDAPS on port 636, because a hardened domain controller rejects a plaintext simple bind on port 389 with
strongerAuthRequired. The domain controller must be reachable as well as the target server, since every run reads the directory to derive the login. - The destination directory must already exist on the server and the connection user must be able to write to it
- The server must be reachable from Infisical, either directly or through an Infisical Gateway
- A Gateway is required to use a health check or a post-sync command, because the Gateway is what executes them. It must be running Infisical CLI v0.43.120 or later
Create a Linux Server sync
- Infisical UI
- API
- In your Application, go to the Certificate Syncs tab and select Create Sync.
- Select the Linux Server option.
-
Configure the Destination:
- Connection: The SSH Connection used to reach the server, or an LDAP Connection to the domain the server is joined to.
- Destination Directory: The absolute path to the directory where certificate files are written, for example
/etc/ssl/certs.
-
Configure the Target Host. This step appears only when the connection is an LDAP Connection, because that connection reaches a whole domain rather than one machine:
- Target Host: The machine this sync delivers to. Servers found in the directory are offered as suggestions, and you can enter a host that isn’t listed. Enter a host name or an IPv4 address. Underscores, ports and IPv6 literals aren’t accepted.
- Port: Leave empty to use 22. Set a value only if the SSH listener is on a non-standard port.
- Trusted Host Keys: Optional. Paste the output of
ssh-keyscan <host>. When set, the sync only connects if the host presents one of these keys.
-
Configure the Sync Options:
- Export Format: Choose PEM to write separate certificate, chain, and key files, or PKCS#12 to write a single password-protected
.pfxbundle. - Certificate File Extension: For PEM, choose
.pem(default) or.crtfor the certificate and chain files. Both hold the same PEM-encoded content, so pick the one the consuming service expects. - Combine Certificate and Chain: For PEM, write the leaf certificate followed by the chain in a single file (a full-chain file, as nginx expects) and skip the separate chain file.
- File Permissions and Private Key Permissions: Octal modes for the delivered certificate and chain files (default
644) and for the private key file (default600). - Owner and Group: Optionally set the owner and group on the delivered files. Changing ownership requires the connection user to be root or to have passwordless sudo.
- PKCS#12 Password: Required when the export format is PKCS#12. It protects the delivered bundle.
- Include Private Key: For PEM, controls whether the private key is written alongside the certificate. The sync fails for a certificate whose key is not available, for example one issued from an external CSR.
- Include Root CA in Certificate Chain: Include the root CA in the delivered chain. Leave it off when the consuming service only needs the intermediates.
- Enable Removal of Certificates: Delete the delivered files from the server when a certificate is removed from the sync, revoked, or expired.
- Certificate Name Schema: The base file name, using placeholders such as
{{commonName}},{{certificateId}}, or{{shortCertificateId}}. The export format adds the extension. A schema with no placeholder can be linked to only one certificate. - Auto-Sync Enabled: Automatically sync certificates when changes occur.
- Export Format: Choose PEM to write separate certificate, chain, and key files, or PKCS#12 to write a single password-protected
-
Configure the Commands, or leave them empty:
- Health check: A command run on the server before any certificate is written, to confirm the host is ready, for example
test -w /etc/ssl/certs. A non-zero exit stops the sync, so nothing is delivered. See health check. - Post-sync command: A command run on the server after the sync delivers a certificate, so the service that uses it picks up the new file, for example
sudo systemctl reload nginx. See post-sync command.
- Health check: A command run on the server before any certificate is written, to confirm the host is ready, for example
-
Configure the Details:
- Name: The name of your sync.
- Description: Optional description.
- Select which certificates should be synced.
- Review and click Create Sync.
Using an LDAP connection for many servers
An SSH Connection stores the target machine’s address alongside its credential, so it reaches exactly one server. Pushing one certificate to fifty servers means fifty connections holding the same credential, and fifty objects to update when that credential is rotated. An LDAP Connection removes that duplication. It’s both the credential and the directory, so one connection serves as many syncs as you have servers. Each sync names its own Target Host, and every sync shares the one credential. When you rotate the service account’s password on the connection, every sync that uses it picks up the new password on its next run with no further action. This works because an Active Directory service account is a single identity. On a domain-joined Linux host, the same username and password that performs the LDAP bind performs the SSH logon, so no second credential is needed. The host must accept domain credentials over SSH, which is what a directory client such as SSSD provides. The Target Host field offers machines read from the directory. The list isn’t closed, because the name a domain controller advertises isn’t always the address you can reach, so you can enter a host that isn’t listed. The value must be a host name or an IPv4 address.The host must accept the DOMAIN\user login form
Infisical logs in to the server as DOMAIN\user, for example CORP\svc-certs. Whether a Linux host
accepts that form depends on how its directory client is configured.
A host joined to the domain with realm join uses the SSSD ad provider, which understands
DOMAIN\user out of the box. A host configured against the directory over LDAP instead uses the
ldap provider, whose default name parsing only understands user@domain, so the login is rejected
before the password is ever checked. Add the domain-qualified form to that host’s sssd.conf:
getent passwd 'CORP\svc-certs' on the server before creating the sync. If that
returns nothing, the sync will fail to authenticate no matter what the connection holds.
Export formats
The file extension is set by the export format, not by the name schema. The name schema only provides the base file name. PEM writes the certificate, chain, and private key (when included) as separate files. The certificate and chain files use the extension you select, either.pem (default) or .crt.
PKCS#12 writes a single password-protected .pfx bundle that contains the certificate, chain, and private key.
For a certificate whose common name is app.example.com, synced to /etc/ssl/certs with the default {{commonName}} name schema, the delivered files are:
How it works
When syncing certificates, Infisical opens an SSH session to the server and, for each certificate, packages it in the chosen export format and writes the resulting files to the destination directory. Files are written atomically over SFTP so a reader never sees a partially written certificate or key.Commands
A sync can run two optional commands on the target server, in that server’s own shell:- A health check runs before any certificate is written and gates the delivery, for example
test -w /etc/ssl/certs. - A post-sync command runs after the delivery has finished, so the service that uses the certificate picks up the new file, for example
sudo systemctl reload nginx.
&&.
infisical --version on the Gateway host to check, and see Gateway deployment for how to upgrade.Available variables
Write a variable where you want this run’s value. Infisical substitutes it before the command is sent to the server, so a command keeps working when the name schema or export format changes.{{certificatePath}} rather than "{{certificatePath}}". A variable that has no value for the run becomes an empty string.
Only the names in this table are substituted. Anything else in double braces is left in the command exactly as you wrote it, so a command that calls a tool with its own braces (helm, jq, a Go template) keeps working, and a misspelled variable reaches the server as literal text rather than silently turning into nothing.
{{certificatePath}} and {{commonName}} name one specific certificate, so a command that uses either can only be saved on a sync with a single certificate linked. Linking a second certificate to such a sync is rejected, as is adding one of these variables to a sync that already has several. To act on every certificate in the run, use {{certificateFiles}}, which lists one path per line.Length limit
Each command is limited to 8192 characters, counted as you write it, before variables are substituted. For anything longer, put the logic in a script on the server and have the command call that script.Least privilege
Both commands run as the account the SSH Connection authenticates with, so constraining that account bounds what either can do. A service reload doesn’t need root. Grant the connection user asudoers rule for that one command instead:
Health check
A sync can only tell you the host wasn’t ready once it has already tried. If the destination directory was renamed or the service that owns it is stopped, you find out from a failed sync, and on a renewal that is the day the certificate was going to expire anyway. A health check moves that discovery earlier. It runs on the target server before any certificate is written. If it exits non-zero, the sync stops there: no files are delivered, no removals happen, and no post-sync command runs. The same check also runs on its own once a day, so a host that stops being ready between syncs is reported when it happens rather than at the next renewal. Write a check that answers a question rather than one that changes something.test -w /etc/ssl/certs and systemctl is-active nginx are good checks. Creating the directory or starting the service is work for the post-sync command.
The check runs on the target server, not on Infisical, and gates everything after it:
Open the sync's Commands step
Write the check
{{certificateFiles}}:Test it, then save the sync
{{pkcs12Password}} is the exception: the export password only exists once a saved sync delivers a certificate, so a test always rejects it.Save the sync once the check passes. On a real run, a failing check fails the sync without delivering anything, and the reason appears as the sync’s last error.Post-sync command
Delivering a certificate file doesn’t make the service use it. NGINX keeps serving the old certificate until something reloads it. A post-sync command is that last step, run for you right after the files land. It runs once per sync run that delivers at least one file. If a sync run doesn’t complete, Infisical may attempt it again and the command runs with it, so prefer a command that is safe to run more than once. The command runs on the target server, not on Infisical, and only after the whole delivery has finished:Open the sync's Commands step
Write the command
{{ in the command field lists the ones available for this sync, so you can pick one instead of remembering the name:Save and trigger a sync
Command FAQ
When exactly does each command run?
When exactly does each command run?
What happens when a command fails?
What happens when a command fails?
Can I run several commands, and what happens if one of them fails?
Can I run several commands, and what happens if one of them fails?
&&.By default the shell only reports the last line’s exit status, so an earlier line that fails is not noticed and the command counts as having succeeded. Start the script with set -e so the first failure stops it and fails the sync:Is there a time limit?
Is there a time limit?
Can a command run twice for the same certificate?
Can a command run twice for the same certificate?
Does a failed health check get retried?
Does a failed health check get retried?
Where do I see the result of the daily health check?
Where do I see the result of the daily health check?
Can I use the health check to prepare the host instead of just checking it?
Can I use the health check to prepare the host instead of just checking it?
Removing certificates
When certificate removal is enabled and a certificate is removed from the sync, revoked, or expired, Infisical deletes exactly the files it delivered for that certificate.FAQ
Can I import certificates from a Linux server back into Infisical?
Can I import certificates from a Linux server back into Infisical?
What happens if the destination directory does not exist?
What happens if the destination directory does not exist?