Home / Alt manpages / ssh-pkcs11-helper(8)

  • ssh-pkcs11-helper(8)
  • Admin command
  • linux

Use OpenSSH's PKCS#11 Helper Through the Right Commands

You will finish with a safe way to check and use OpenSSH's PKCS#11 support without treating its helper as a normal interactive command. The helper is an internal program: ssh, ssh-agent and ssh-keygen start it when they need to access keys supplied by a PKCS#11 token.

Allow about fifteen minutes. You need the OpenSSH client package, a PKCS#11 provider library and access to a token if you want to test authentication. The examples below do not change system files, agent configuration or token contents. Do not type a token PIN into a shared terminal or paste it into a script.

1. Check the installed package and helper

Start with ordinary, read-only checks. On this Ubuntu installation, the package is OpenSSH client 1:9.6p1-3ubuntu13.19, and the helper is installed outside the normal command search path:

$ dpkg-query -W -f='${Package} ${Version}\n' openssh-client
openssh-client 1:9.6p1-3ubuntu13.19
$ dpkg -L openssh-client | grep '/ssh-pkcs11-helper$'
/usr/lib/openssh/ssh-pkcs11-helper

Checkpoint: the path and version can differ on another distribution. Use the output from your machine in later troubleshooting rather than assuming that /usr/lib/openssh is universal.

2. Do not launch the helper as a shell utility

The helper accepts only -v, which enables diagnostic messages. The manual explicitly says it is not intended to be invoked directly. It speaks the private protocol expected by its OpenSSH callers, so a direct launch is not a useful token test and may simply wait for protocol input.

Use the installed path only to confirm that the package supplied it:

$ test -x /usr/lib/openssh/ssh-pkcs11-helper && echo 'helper is executable'
helper is executable

There is no configuration to edit and no service to restart for this check. If the file is missing, reinstall or repair the package through your normal package-management process. Do not copy a helper binary from another host.

3. Ask ssh to use a PKCS#11 provider

The user-facing entry point for an SSH connection is the -I option. It selects the PKCS#11 shared library that ssh should use for user authentication. Replace the placeholder with the provider path supplied by your token vendor or system administrator:

$ PKCS11_PROVIDER='/path/to/vendor-pkcs11.so'
$ test -r "$PKCS11_PROVIDER" && echo 'provider is readable'
provider is readable
$ ssh -I "$PKCS11_PROVIDER" -vv [email protected]

The final command is a connection attempt and may prompt for the token PIN or host-key confirmation. Use a real test account and host in place of [email protected]. The -vv setting belongs to ssh; the helper receives increased verbosity automatically when its caller is in debug mode. Stop with Ctrl-C if the destination is not the host you intended to test.

Expected diagnostic lines vary by provider and token. Look for PKCS#11 loading and key-offer messages in the debug output, then check the final SSH exit status:

$ printf 'ssh exit status: %s\n' "$?"
ssh exit status: 0

Status 0 means that the SSH session ended successfully, not that every key on the token was usable. A provider load error, an unavailable token or a rejected PIN is a separate failure. Do not keep retrying a PIN blindly: tokens can lock after too many failed attempts.

4. Use ssh-agent when several connections need the token

If an agent should hold the PKCS#11 keys, use ssh-add, not the helper. Its -s option adds keys from a PKCS#11 shared library:

$ eval "$(ssh-agent -s)"
$ ssh-add -s "$PKCS11_PROVIDER"
Enter passphrase for PKCS#11:
Card added: /path/to/vendor-pkcs11.so
$ ssh-add -L

The agent process changes your shell environment and may keep access to token-backed keys until the agent exits. Check the listed public keys before using them. If the provider asks for a PIN, enter it only in the prompt from the trusted terminal.

When this temporary agent is no longer needed, remove its keys and stop it. These commands affect the agent started in this shell, not the token:

$ ssh-add -D
All identities removed.
$ ssh-agent -k

Do not use ssh-add -D if the agent is shared with other sessions unless removing every identity is intended. For a shared agent, identify the correct process and use the least disruptive cleanup available.

5. Troubleshoot the boundary between caller and helper

Keep the layers separate. A missing helper usually indicates a damaged or incomplete OpenSSH client installation. A provider error concerns the shared library. A token or PIN error concerns the device or its access policy. An authentication failure can still be caused by the remote account, authorised keys or server configuration.

Repeat the read-only checks first:

$ command -v ssh ssh-agent ssh-add
/usr/bin/ssh
/usr/bin/ssh-agent
/usr/bin/ssh-add
$ dpkg -L openssh-client | grep '/ssh-pkcs11-helper$'
/usr/lib/openssh/ssh-pkcs11-helper

Do not run the helper with -vvv directly. The helper supports at most three -v options, but its caller controls when those diagnostics are passed. Use ssh -vvv or the relevant ssh-agent or ssh-keygen debug mode instead, and review logs for token identifiers or usernames before sharing them.

Done means

  • You confirmed the installed OpenSSH client version and helper path.
  • You understand that ssh-pkcs11-helper is an internal protocol helper, not an interactive utility.
  • You selected the provider with ssh -I or ssh-add -s.
  • You tested the provider with an intended destination and inspected the caller's exit status.
  • You avoided exposing a PIN and stopped a temporary agent when it was no longer needed.