Update, October 2026: the XML flat-file provider described below is retired. Public keys now live in the database (admin add-key), and an upgrade moves the users and keys of users.xml there for you. See the User's Guide.
Password authentication for SFTP works, until it doesn’t. A password can be guessed. It can be phished. It can be pasted into a Slack channel by someone who meant to paste a URL. Public-key authentication eliminates those failure modes entirely: the secret never crosses the network, so there is nothing to intercept, replay, or accidentally leak in a chat window.
This post walks through the full lifecycle — generating a keypair, getting the public half onto the server, what happens at login time, and how to rotate keys when the time comes.
Step 1: Generate the keypair
A keypair is two files: a private key that stays on the client machine and a public key that goes to the server. The private key proves identity; the public key verifies it.
On any machine with OpenSSH installed:
ssh-keygen -t ed25519 -C "alice@acme.com"
This produces two files. The private key (id_ed25519) stays where it is — never copy it anywhere. The public key (id_ed25519.pub) is the one you distribute. It looks like this:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... alice@acme.com
Three fields, space-separated: key type, base64-encoded key data, and an optional comment. That single line is the only thing the server needs.
Which key type? Ed25519 is the modern default — small keys, fast verification, no parameter-choice pitfalls. RSA (2048-bit minimum, 4096 recommended) remains widely supported for environments that require it. ECDSA with NIST P-256, P-384, or P-521 curves is a third option. DSA is legacy and should not be used for new deployments.
Step 2: Register the public key on the server
The server needs to know which public keys belong to which user. How that registration works depends on the authentication provider.
In Stylus SFTP Server, there are three paths:
- JDBC provider (the most common). Keys are stored in the
sftp_user_keystable — one row per key per user. Register a key through the Web Admin, the Swing admin GUI, or the CLI:
The server can also generate the entire keypair for you withsss-admin --add-key alice "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... alice@acme.com"--generate-keypair, writing the private key to a file and registering the public half in the database in one step. The generated key is always Ed25519. - XML flat-file provider. Keys go in
conf/users.xmlunder a<public-keys>element:
The server hot-reloads the file whenever it changes — no restart required.<user> <username>alice</username> <public-keys> <public-key>ssh-ed25519 AAAAC3NzaC1lZDI1... alice@acme.com</public-key> </public-keys> </user> - LDAP provider. The server reads keys from a configurable LDAP attribute (commonly
sshPublicKeyon the user object). Key management happens through your existing directory tooling.
A user can have multiple keys registered at once. That is normal — one per workstation or automation endpoint.
Step 3: What happens at login
When an SFTP client connects with a public key, the SSH protocol runs a challenge-response exchange. The client proves it holds the private key without ever transmitting it. The server’s job is to verify that the signature matches one of the registered public keys for that username.
In Stylus SFTP Server, the authentication path is:
- The client presents a username and a public key.
- The server loads all registered public keys for that user — from the database, the XML file, or LDAP, depending on the active provider.
- It compares the presented key against each registered key byte-for-byte.
- If a match is found and the signature is valid, authentication succeeds. If not, the attempt is rejected.
One important difference from password authentication: failed key attempts do not trigger account lockout. Key-based authentication is not vulnerable to brute force — there is no secret to guess — so lockout protection is unnecessary and would only cause problems for legitimate clients presenting multiple keys in sequence.
Step 4: Rotation
Keys should be rotated when someone leaves the team, when a workstation is decommissioned, or on a schedule your security policy defines. The process is straightforward because public-key authentication supports overlap:
- Generate a new keypair on the client.
- Register the new public key on the server (the old key stays active).
- Verify that the new key works.
- Remove the old public key from the server.
There is no moment of downtime. Both keys are valid simultaneously during the transition.
In Stylus SFTP Server, adding and removing keys through the Web Admin, CLI, or REST API produces audit records — public_key_added and public_keys_removed — so you have a trail of who changed which key and when.
What to remember
- The private key never leaves the client machine. If it does, generate a new one.
- Ed25519 is the best default for new deployments. RSA is the safe fallback for legacy systems.
- Register multiple keys per user when they connect from more than one machine.
- Rotate on role change, on device change, or on your compliance calendar — not “when we get around to it.”
- Every key operation is audited. Use the trail when you need to prove who had access and when.