How to Install and Configure an SSH Server on Ubuntu 26.04

Install the OpenSSH server (openssh-server) to log in to a machine remotely over SSH. The installation command on Ubuntu 26.04 is the same as on 24.04. But OpenSSH is now version 10.2p1, and systemd socket activation is the default.

This post installs the OpenSSH server on Ubuntu 26.04 and then sets up key-based authentication, hardening, and the firewall.

Install openssh-server

sudo apt update
sudo apt install -y openssh-server
Ubuntu 26.04 SSH server: apt install openssh-server output

The package maintainer script generates the host keys and adds ssh.socket to sockets.target. The 26.04 package also includes sshd-keygen.service, which generates the host keys.

Check socket activation

systemctl status ssh.socket ssh.service --no-pager
Ubuntu 26.04 SSH server: systemctl status of ssh.socket and ssh.service

Right after the installation, ssh.service is disabled and inactive (dead). systemd (PID 1) listens on port 22 through ssh.socket.

sudo ss -tlnp | grep -E 'State|:22 '
ssh -V
Ubuntu 26.04 SSH server: ss shows systemd listening on port 22, and ssh -V
UnitRoleState after installation
ssh.socketListens on the port and waits for the first connectionenabled, active (listening)
ssh.serviceThe sshd process. Starts at the first connectiondisabled, inactive (dead)

First connection and host key verification

Log in from the client with a password for the first time. In the commands below, $ID is the account on the server and $PW is its password. When SSH asks about the host key, enter yes, then enter $PW.

ssh $ID@$TARGET_IP
systemctl is-active ssh.service
Ubuntu 26.04 SSH server: first login with host key prompt

Before you enter yes, check the fingerprint on the server. The fingerprint from ssh-keygen -lf must match the one on the client.

ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
systemctl status ssh.service --no-pager
Ubuntu 26.04 SSH server: host key fingerprint and ssh.service triggered by ssh.socket

After the first connection, ssh.service is started with TriggeredBy: ssh.socket and keeps running.

Set up key-based authentication

Generate an Ed25519 key pair on the client. Do not leave the passphrase empty.

ssh-keygen -t ed25519 -C "$ID@client"
Ubuntu 26.04 SSH server: ssh-keygen generates an Ed25519 key

Add the public key to ~/.ssh/authorized_keys on the server with ssh-copy-id. You enter $PW once in this step.

ssh-copy-id $ID@$TARGET_IP
Ubuntu 26.04 SSH server: ssh-copy-id adds the public key

Log in again with the key, and check the authentication method and the key exchange (kex) algorithm.

ssh -v $ID@$TARGET_IP true 2>&1 | grep -E 'kex: algorithm|Server accepts|Authenticated'
Ubuntu 26.04 SSH server: ssh -v shows kex algorithm and publickey authentication

The key exchange algorithm depends on the client version. With the OpenSSH 10.2p1 client of 26.04, SSH selects an ML-KEM based algorithm.

ClientNegotiated key exchange algorithm
Ubuntu 24.04 (OpenSSH 9.6p1)sntrup761x25519-sha512@openssh.com
Ubuntu 26.04 (OpenSSH 10.2p1)mlkem768x25519-sha256

Both are hybrid post-quantum algorithms. You do not need to change the server configuration.

Harden sshd with sshd_config.d

Line 24 of /etc/ssh/sshd_config has Include /etc/ssh/sshd_config.d/*.conf. The directory is empty after the installation. Keep the main file unchanged and put your settings in a new drop-in file.

sudo tee /etc/ssh/sshd_config.d/10-hardening.conf <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
MaxAuthTries 3
AllowUsers $ID
EOF
sudo sshd -t && echo syntax-ok
sudo sshd -T | grep -E '^(passwordauth|kbdinteractiveauth|permitrootlogin|maxauthtries|allowusers)'
sudo systemctl restart ssh
Ubuntu 26.04 SSH server: sshd_config.d drop-in file and sshd -T output

sshd -t checks only the syntax. To see the effective values, use sshd -T.

OptionValueEffect
PasswordAuthenticationnoDisables password authentication
KbdInteractiveAuthenticationnoDisables the PAM keyboard-interactive path that asks for a password
PermitRootLoginnoDisables root login
MaxAuthTries3Limits authentication attempts per connection to 3
AllowUsers$IDAllows only the listed users to log in

From the client, a password login and a root login both fail. A key login still works.

ssh -o PubkeyAuthentication=no $ID@192.168.0.57
ssh root@192.168.0.57
ssh $ID@192.168.0.57 hostname
Ubuntu 26.04 SSH server: password and root logins rejected, key login accepted

If several files set the same option, the first value that sshd reads wins. A file named 05-legacy.conf sorts first, so it changes the result.

$ echo 'PasswordAuthentication yes' | sudo tee /etc/ssh/sshd_config.d/05-legacy.conf
$ ls /etc/ssh/sshd_config.d/
05-legacy.conf
10-hardening.conf
$ sudo sshd -T | grep ^passwordauthentication
passwordauthentication yes
$ sudo rm /etc/ssh/sshd_config.d/05-legacy.conf
$ sudo sshd -T | grep ^passwordauthentication
passwordauthentication no

Check the login log

sudo journalctl -u ssh.service -n 6 --no-pager
Ubuntu 26.04 SSH server: journalctl log of ssh.service

sshd rejects the root login with not listed in AllowUsers. Since OpenSSH 9.8, each connection runs in a separate sshd-session process, so the log shows this name.

Configure the ufw firewall

ufw is installed but disabled by default. Allow SSH first, then enable ufw.

sudo ufw app info OpenSSH
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status verbose
Ubuntu 26.04 SSH server: ufw allow OpenSSH and ufw status

The OpenSSH application profile opens 22/tcp.

Cautions

  • In a remote session, run ufw allow before ufw enable. In the other order, you lose the current SSH connection.
  • Test the key login in a new terminal before you disable password authentication. Keep the existing session open. If the key login fails, use that session to revert the configuration.
  • Check the files in sshd_config.d before you change settings. The directory is empty after installation, but other packages or management tools can add files. The first value read wins, so check the effective values with sshd -T.
  • Do not accept the host key prompt without checking. Compare it with the fingerprint from ssh-keygen -lf on the server, then enter yes.

Conclusion

The command to install the SSH server on 26.04 is the same as on 24.04. The differences are socket activation and the OpenSSH 10 defaults. Put your settings in a sshd_config.d drop-in file and check the effective values with sshd -T.

This is a referral link. I may receive credit if you sign up, at no extra cost to you.

Try it on a cloud server — Deploy Ubuntu on Vultr

References

Leave a Reply