Configure OpenSSH Host-Based Authentication on Linux

Deepak Prasad
Tested on RHEL 10.2 client (vm1.lab.example, openssh-clients 9.9p1-27.el10_2, openssh-keysign 9.9p1-27.el10_2) → Ubuntu 26.04 server (vm2.lab.example, openssh-server 10.2p1-2ubuntu3.6); SELinux enforcing on the RHEL client
Package openssh-clients, openssh-server, openssh-keysign (RHEL/Fedora subpackage)
Applies to Linux hosts with OpenSSH 8.x–10.x client and server
Privilege Root or sudo on client and server for host keys, ssh_config, and sshd_config
Scope End-to-end OpenSSH host-based authentication across two hosts: client ssh-keysign, server HostbasedAuthentication, centrally managed shosts.equiv and /etc/ssh/ssh_known_hosts, hostname/DNS alignment, per-account Match blocks, and troubleshooting. Does not replace SSH user keys or certificate-based access for workstations.
Related guides OpenSSH authentication methods
SSH key authentication
OpenSSH certificate authentication
Test SSH connection
OpenSSH tutorial
Short on time?Beta Get the gist of this 14-minute read in seconds, then ask follow-up questions

Host-based SSH authentication lets a trusted client machine prove its identity with the host's private key, then log in when the server authorizes that client hostname and remote username pair. It is not the same as normal SSH public-key login, where each user keeps a personal key in ~/.ssh/.

This walkthrough uses a two-host RHEL 10 client and Ubuntu 26.04 server lab with SELinux left in enforcing mode on the client. You will enable ssh-keysign on the source host, trust the client Ed25519 host key on the target after verifying its fingerprint, and authorize hbalab through /etc/ssh/shosts.equiv.


What is SSH host-based authentication?

Host-based authentication answers a different question than user public-key authentication:

  • What is trusted — the client host (machine identity), not a user's personal keypair
  • Who maps to whom — for system-wide /etc/ssh/shosts.equiv, the remote username must match the local account you request on the ssh command line
  • How the client proves the host — OpenSSH signs the attempt with /etc/ssh/ssh_host_* private keys through ssh-keysign (you do not run ssh-keysign yourself; the ssh command invokes it when host-based authentication needs a signature)
  • How the server verifies the host — the signature must match a trusted client host public key in the administrator-controlled host-key store

This is also separate from server host-key verification during a normal SSH connection. Normal SSH first lets the client verify the server. Host-based authentication then lets the server verify the client machine before deciding whether the requested user may log in.


How host-based authentication works

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────────────────┐
│ ssh client      │ ──► │ ssh-keysign      │ ──► │ signs with client host      │
│ (user session)  │     │ reads /etc/ssh/  │     │ private key (root-only)     │
│                 │     │ ssh_host_*_key   │     │                             │
└─────────────────┘     └──────────────────┘     └─────────────────────────────┘
         │                                                    │
         │              hostbased userauth packet             │
         ▼                                                    ▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ sshd on server                                                              │
│  1) verify signature against /etc/ssh/ssh_known_hosts (client host key)     │
│     when IgnoreUserKnownHosts yes (recommended for central trust)           │
│  2) match client hostname + remote user in /etc/ssh/shosts.equiv            │
│  3) open session as the local user named on ssh user@server                  │
└─────────────────────────────────────────────────────────────────────────────┘
Component Role
/etc/ssh/ssh_host_*_key on the client Machine private keys; root-readable only
/usr/libexec/openssh/ssh-keysign (RHEL) or /usr/lib/openssh/ssh-keysign (Debian/Ubuntu) Signs host-based proofs; setuid root; not invoked directly by users
HostbasedAuthentication + EnableSSHKeysign in /etc/ssh/ssh_config Lets the client offer host-based authentication
/etc/ssh/ssh_known_hosts on the server Administrator-controlled trusted client host public keys
/etc/ssh/shosts.equiv on the server System-wide host/user authorization
HostbasedAuthentication + IgnoreUserKnownHosts in /etc/ssh/sshd_config Accept host-based logins; keep client host-key trust central

On RHEL 10, ssh-keysign ships in the openssh-keysign subpackage and is not installed with openssh-clients alone.


Host-based vs public-key vs SSH certificate authentication

Topic Host-based Public-key (user) SSH certificates
Identity authenticated Client host + matching remote username Individual user CA-signed user (or host) identity
Private key location (client) /etc/ssh/ssh_host_*_key ~/.ssh/id_* ~/.ssh/id_* (often cert-backed)
Server trust configuration /etc/ssh/ssh_known_hosts + shosts.equiv ~/.ssh/authorized_keys TrustedUserCAKeys / HostCertificate
Per-user scalability Poor — machine trust can cover listed account pairings Good — one key per user Very good — CA issues credentials
Hostname/DNS dependency High — name mismatch breaks auth Low for user authorization — the user's key is matched in authorized_keys; normal server host-key verification is still separate Low for user certs
Typical use case Small managed server mesh, batch hosts Daily admin access, CI, git deploy Large cloud or enterprise fleets
Recommended for new large deployments? No Yes (with passphrases + agent) Often best at scale

Host-based authentication fits only when machine identity is meaningful and the trusted client fleet stays small. For day-to-day access, start with SSH key authentication. For many hosts and users, compare OpenSSH certificate authentication before enabling machine-wide trust.


Should you use host-based authentication?

Suitable Prefer something else
Small controlled server-to-server mesh User workstations and laptops
Dedicated batch or jump servers General interactive admin access
Existing legacy host-trust estates New large fleets
Machine identity is meaningful in policy Per-user accountability and easy revocation matter most

Treat every trusted client host as a high-value asset. Compromise of that host can expose every account pairing listed in shosts.equiv, not just one user's key.


Lab environment

The captured logins use two separate VMs on 192.168.56.0/24. SELinux stays Enforcing on the RHEL client; do not disable it for this procedure.

Role Hostname Address OS
SSH client (source) vm1.lab.example 192.168.56.116 RHEL 10.2
SSH server (target) vm2.lab.example 192.168.56.121 Ubuntu 26.04
Test user hbalab local account on vm2 used for login

Both hosts need matching forward and reverse names in /etc/hosts or DNS. Before you configure trust files, confirm reachability with the layered checks in test an SSH connection.

Example /etc/hosts on both client and server:

text
192.168.56.116  vm1.lab.example vm1
192.168.56.121  vm2.lab.example vm2

The test command run from the client:

bash
ssh hbalab@vm2.lab.example

Prerequisites

Verify OpenSSH and ssh-keysign

On the client (RHEL 10), confirm packages and install the signing helper if needed:

bash
rpm -q openssh-clients openssh-keysign
output
openssh-clients-9.9p1-27.el10_2.x86_64
openssh-keysign-9.9p1-27.el10_2.x86_64

If openssh-keysign is missing, install it with dnf:

bash
sudo dnf install openssh-keysign

The helper must be setuid root:

bash
ls -l /usr/libexec/openssh/ssh-keysign
output
-r-sr-xr-x. 1 root root 338112 Aug 21 05:30 /usr/libexec/openssh/ssh-keysign

On the server (Ubuntu), you only need openssh-server running. Host-based authentication does not require sshd on the client.

bash
dpkg -l openssh-server | tail -1
output
ii  openssh-server 1:10.2p1-2ubuntu3.6 amd64        secure shell (SSH) server, for secure access from remote machines

Verify client host keys

Host-based authentication needs machine keys under /etc/ssh on the client:

bash
sudo ls -l /etc/ssh/ssh_host_ed25519_key /etc/ssh/ssh_host_ed25519_key.pub

If keys are missing, generate them:

bash
sudo ssh-keygen -A

Host private keys must stay mode 600 and owned by root.

Verify hostname resolution

On the server, forward and reverse lookups for the client address should return vm1.lab.example:

bash
getent hosts vm1.lab.example
output
192.168.56.116  vm1.lab.example vm1

Reverse lookup on the server must agree:

bash
getent hosts 192.168.56.116
output
192.168.56.116  vm1.lab.example vm1

If reverse lookup returns only the IP address, host-based authentication fails with userauth_hostbased mismatch until you fix naming (covered later).

Trust files at a glance

File Host Purpose
/etc/ssh/ssh_config Client HostbasedAuthentication, EnableSSHKeysign
/etc/ssh/sshd_config Server HostbasedAuthentication, IgnoreUserKnownHosts, IgnoreRhosts
/etc/ssh/ssh_known_hosts Server Trusted client host public keys (central admin control)
/etc/ssh/shosts.equiv Server System-wide host/user authorization
~/.shosts Server Per-user authorization only when IgnoreRhosts allows it (not used in this lab)

Configure the SSH client

Client changes live in /etc/ssh/ssh_config. They affect outbound ssh sessions only; you do not restart sshd on the client after editing this file.

Enable host-based authentication and ssh-keysign

Add these settings to the global /etc/ssh/ssh_config (or a snippet under /etc/ssh/ssh_config.d/ included from the global file):

text
Host *
    HostbasedAuthentication yes
    EnableSSHKeysign yes

EnableSSHKeysign is accepted only in the global client configuration, not in a per-user ~/.ssh/config file.

WARNING
EnableSSHKeysign yes allows unprivileged users on the client to request host-key signatures through ssh-keysign. Enable it only on hosts you treat as controlled signing endpoints.

Verify effective client settings

ssh -G prints the configuration ssh will use for the server hostname:

bash
ssh -G vm2.lab.example | grep -iE 'hostbasedauthentication|enablesshkeysign'
output
hostbasedauthentication yes
enablesshkeysign yes

Both values should be yes before you test from the client.


Configure the SSH server

All steps below run on vm2 (vm2.lab.example, the SSH server).

Enable host-based authentication

Create /etc/ssh/sshd_config.d/99-hostbased.conf (or edit sshd_config) with a centrally managed baseline:

text
HostbasedAuthentication yes
IgnoreUserKnownHosts yes
IgnoreRhosts yes
  • IgnoreUserKnownHosts yes — client machine trust comes only from /etc/ssh/ssh_known_hosts, not from individual users' ~/.ssh/known_hosts
  • IgnoreRhosts yes — ignore per-user ~/.rhosts and ~/.shosts; the system-wide /etc/ssh/shosts.equiv is still honored

That gives you two administrator-controlled questions on the server:

  • /etc/ssh/ssh_known_hosts — which client machines do we trust?
  • /etc/ssh/shosts.equiv — which host and user combinations may log in?

Confirm effective values:

bash
sudo sshd -T | grep -iE 'hostbasedauthentication|ignoreuserknownhosts|ignorerhosts'
output
hostbasedauthentication yes
ignoreuserknownhosts yes
ignorerhosts yes

See OpenSSH authentication methods for how these directives interact with Match blocks.

Configure central host and user authorization

Create /etc/ssh/shosts.equiv on the server with one line per authorized client hostname and remote username:

text
vm1.lab.example hbalab

Set ownership and mode:

bash
sudo chown root:root /etc/ssh/shosts.equiv
sudo chmod 644 /etc/ssh/shosts.equiv

Here both sides use the same username: hbalab on vm1 connects as hbalab on vm2. That is the simple system-wide shosts.equiv model used in this guide. Mapping one username to a different account requires per-user ~/.shosts, which we are deliberately not using here.

Trust the client host key

The server must trust the client machine's public host key. Copy it from the client over a trusted administrative path — do not copy the private /etc/ssh/ssh_host_ed25519_key.

On vm1 (the client), display the Ed25519 public host key:

bash
sudo cat /etc/ssh/ssh_host_ed25519_key.pub
output
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEeTyvFvs5FNVgu2mNGqDZwoEhN08xwXTKCLaTgy1Xul

Verify its fingerprint before you install it on the server:

bash
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
output
256 SHA256:m0IbDhiWVYyfyiyaMJJjBMDlxsm5n5gRMU1SgW9gV4A no comment (ED25519)

On vm2 (the server), add one line to /etc/ssh/ssh_known_hosts with the client hostname and the public key from the step above:

text
vm1.lab.example ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEeTyvFvs5FNVgu2mNGqDZwoEhN08xwXTKCLaTgy1Xul

One compatible trusted client host key is sufficient. Add other key types only when compatibility requirements justify them.

If sshd is already running on the client, ssh-keyscan -t ed25519 vm1.lab.example can fetch the same public key — but that approach fails with Connection refused when the client has no SSH server listening, which is normal for a dedicated client host.

Validate and reload sshd

Run a syntax check before you reload:

bash
sudo sshd -t

A silent exit means sshd accepts the configuration files. Reload the running daemon:

bash
sudo systemctl reload ssh

Use the systemctl command restart only when reload is insufficient.


Test host-based authentication

From vm1, log in as hbalab and force host-based authentication so other methods do not mask failures. Use StrictHostKeyChecking=accept-new only in the lab so the client's first connection to the server's host key can proceed — that step is separate from host-based client trust on the server.

bash
ssh -vv -o StrictHostKeyChecking=accept-new \
  -o PreferredAuthentications=hostbased \
  -o PubkeyAuthentication=no \
  -o PasswordAuthentication=no \
  hbalab@vm2.lab.example hostname -f

A successful trace shows host-based authentication offered, attempted, and accepted:

output
debug1: Next authentication method: hostbased
debug1: userauth_hostbased: trying hostkey ssh-ed25519 SHA256:m0IbDhiWVYyfyiyaMJJjBMDlxsm5n5gRMU1SgW9gV4A using sigalg ssh-ed25519
Authenticated to vm2.lab.example ([192.168.56.121]:22) using "hostbased".
debug1: Remote: Accepted for vm1.lab.example [192.168.56.116] by /etc/ssh/shosts.equiv.
vm2.lab.example

If you never see Next authentication method: hostbased, the problem is on the client (HostbasedAuthentication, EnableSSHKeysign, or missing openssh-keysign). If host-based is attempted but rejected, investigate the server (shosts.equiv, /etc/ssh/ssh_known_hosts, hostname/DNS). Remove the PreferredAuthentications and PubkeyAuthentication overrides after the test; they are diagnostic only.


Restrict host-based authentication to specific accounts

Host-based trust is not open to every account by default. The server still requires a shosts.equiv line, a matching local account, and HostbasedAuthentication yes for that account.

Limit which accounts accept host-based logins with a Match User block in sshd_config:

text
Match User hbalab
    HostbasedAuthentication yes
    PasswordAuthentication no

Match User backupsvc
    HostbasedAuthentication no
    PubkeyAuthentication yes

Only place valid directives inside Match. Evaluate the effective policy with:

host and addr describe the incoming client connection, not the SSH server. Simulate a login from vm1 with:

bash
sudo sshd -T -C user=hbalab,host=vm1.lab.example,addr=192.168.56.116 | grep -iE 'hostbasedauthentication|passwordauthentication|pubkeyauthentication'
output
passwordauthentication no
pubkeyauthentication yes
hostbasedauthentication yes

Adjust user=, host=, and addr= to mirror the client hostname and source address. Add laddr=192.168.56.121,lport=22 when you need to match rules tied to the local server endpoint.


Hostname and DNS requirements

Verify forward and reverse resolution

Host-based authentication compares the client hostname in the authenticated request against names in shosts.equiv and /etc/ssh/ssh_known_hosts. Keep the same form everywhere — short name (vm1) or FQDN (vm1.lab.example), not a mix.

On the server, confirm both directions for the client address:

bash
getent hosts vm1.lab.example
getent hosts 192.168.56.116

Both commands should return vm1.lab.example for 192.168.56.116. Multi-homed clients must use the address and hostname pairing you authorized, or reverse DNS on the server must return the name listed in shosts.equiv.

Fix userauth_hostbased mismatch

When reverse lookup fails, sshd may log:

text
userauth_hostbased mismatch: client sends vm1.lab.example, but we resolve 192.168.56.116 to 192.168.56.116

Fix forward and reverse records in DNS or /etc/hosts first. Consistent naming makes the trust relationship easier to audit.

If you cannot correct reverse DNS immediately, set on the server:

text
HostbasedUsesNameFromPacketOnly yes

That skips the server's reverse-DNS-derived hostname check and uses the hostname from the authenticated host-based request instead. The client must still prove possession of the corresponding trusted host private key. Prefer fixing DNS first; UseDNS yes is not the primary fix for this error class.


Security considerations

Host-based authentication concentrates risk at the machine layer:

  • Compromise of a trusted client exposes every shosts.equiv pairing you listed, not just one user's key
  • Host private keys in /etc/ssh are more sensitive than a single user key because ssh-keysign can sign for any local user session on the client
  • Keep the trust list small — one jump or batch host, not a subnet
  • Rotate host keys deliberately — update /etc/ssh/ssh_known_hosts when a client host key changes
  • Leave SELinux enforcing on RHEL — fix contexts instead of disabling MAC

For most new designs, SSH user keys or certificates provide clearer revocation and a smaller blast radius.


Troubleshooting

Symptom Likely cause What to check
hostbased never appears in ssh -vv Client not offering host-based auth HostbasedAuthentication, EnableSSHKeysign, openssh-keysign, ssh -G
hostbased attempted then rejected Server trust, authorization, or name mismatch shosts.equiv, /etc/ssh/ssh_known_hosts, getent hosts, server logs
Permission denied (...,hostbased) Missing shosts.equiv line, username mismatch, or untrusted host key Line format, Ed25519 entry in ssh_known_hosts
ssh_keysign: not installed Helper package missing on RHEL dnf install openssh-keysign
userauth_hostbased mismatch Reverse DNS does not match shosts.equiv name /etc/hosts on server, HostbasedUsesNameFromPacketOnly
Authentication refused: bad ownership or modes Trust file permissions too open shosts.equiv root-owned 644
Host key verification failed (client side) Server host key not in client known_hosts Normal server identity check; use accept-new in lab only

No matching host-based algorithm

If verbose output shows host-based attempted but no acceptable key type remains, check algorithm support on the client:

bash
ssh -Q HostbasedAcceptedAlgorithms
output
ssh-ed25519
ecdsa-sha2-nistp256
rsa-sha2-256
rsa-sha2-512

On the server, align HostbasedAcceptedAlgorithms with the client host key you installed. Older documentation may reference HostbasedAcceptedKeyTypes; on OpenSSH 9.x and 10.x use HostbasedAcceptedAlgorithms.


Summary

OpenSSH host-based authentication trusts a client machine through its host keys and ssh-keysign, then authorizes a matching host/username pair in /etc/ssh/shosts.equiv before opening a local session with the same account name. It is distinct from user public-key login and from SSH certificates.

On the client, enable HostbasedAuthentication and EnableSSHKeysign in global /etc/ssh/ssh_config and install openssh-keysign on RHEL. On the server, set HostbasedAuthentication yes, IgnoreUserKnownHosts yes, and IgnoreRhosts yes; verify the client Ed25519 fingerprint before adding it to /etc/ssh/ssh_known_hosts; maintain a minimal shosts.equiv. Reload sshd after server changes only.

When ssh -vv never shows hostbased, troubleshoot the client (HostbasedAuthentication, EnableSSHKeysign, openssh-keysign). When host-based is attempted but rejected, check server authorization, the trusted client key in /etc/ssh/ssh_known_hosts, and hostname resolution. For new fleets, prefer SSH user keys or certificates.


References


Frequently Asked Questions

Is host-based authentication the same as public-key authentication?

No. Public-key authentication verifies a user keypair in authorized_keys. Host-based authentication verifies the client machine host key and a shosts.equiv mapping with matching usernames.

Does host-based authentication authenticate the host or the user?

Both, in sequence. The client host proves machine identity with host keys; the server then checks whether that hostname and remote username pair may open the same-named local account.

Why is ssh-keysign required?

Host private keys are root-readable only. ssh-keysign runs setuid root so an unprivileged ssh process can obtain a host signature without exposing the key material to every user.

Is UseDNS yes required?

No. Fix forward and reverse naming with /etc/hosts or DNS first. HostbasedUsesNameFromPacketOnly addresses name-matching when reverse DNS cannot be corrected immediately.

Is .rhosts required?

No. This lab uses /etc/ssh/shosts.equiv with IgnoreRhosts yes, which still honors the system-wide file while ignoring per-user .rhosts and .shosts.

Can I restrict host-based authentication to one user?

Yes. Combine a minimal shosts.equiv, matching local accounts, and Match User blocks that enable host-based authentication only where needed.

Is host-based authentication still supported by OpenSSH?

Yes. HostbasedAuthentication remains available and defaults to no on the server; ssh-keysign remains the signing helper on current OpenSSH builds.

Should I use host-based authentication or SSH certificates?

For new large environments, SSH certificates (or per-user keys with proper lifecycle management) scale and audit more cleanly. Host-based trust fits only small, tightly managed server-to-server cases.

Finished reading?Beta Get the key takeaways in seconds, then ask follow-up questions
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware.

  • Debian
  • Ubuntu
  • Linux
  • Red Hat Enterprise Linux
  • Shell Script
  • System Administration