Install and Enable SSH
Run these on the server itself, through your provider's console if SSH does not work yet:
sudo apt update
sudo apt install openssh-server
sudo systemctl enable --now ssh.socket
The package is openssh-server, and the service on Ubuntu and Debian is called ssh (Ubuntu 26.04 also accepts sshd, the name used on AlmaLinux and Rocky Linux). Installing the package already enables and starts SSH; the last line only makes sure, by enabling the socket unit described below at every boot and starting it right away.
Check That It Is Running
systemctl status ssh
sudo ss -ltnp | grep ':22'
The second command lists the listening sockets on port 22, usually one for IPv4 and one for IPv6. The process shown can be systemd rather than sshd, for the reason in the next section. The columns are explained in ss command.
Socket Activation on Recent Releases
Since Ubuntu 22.10, including 24.04 LTS and 26.04 LTS, SSH starts through a systemd socket unit, ssh.socket: systemd holds the port open and starts the ssh service when the first connection arrives. That has two practical effects:
- Status:
systemctl status sshshows the service as inactive until the first connection, while the socket is already active and listening. - Port changes: on 24.04 and later the socket reads the port from
/etc/ssh/sshd_config, so after changing it, reload systemd and restart the socket; restarting only the service does not move the port.
systemctl is-enabled ssh.socket
sudo systemctl daemon-reload
sudo systemctl restart ssh.socket
An administrator can switch socket activation off, so check with the first command: enabled means the socket is in use. The full procedure is in how to change the SSH port, and restarts in how to restart the SSH service.
Allow SSH in UFW Before Enabling the Firewall
Warning: switching UFW on without a rule for SSH cuts your session and locks you out. Add the rule first:
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status
OpenSSH is the application profile for port 22. If SSH runs on another port, allow that port instead, for example sudo ufw allow 2222/tcp. Keep the current session open and test a new login from a second terminal. If your provider also has a firewall in front of the server, open the port there as well. See UFW firewall setup.
Make the First Connection
On the server, find its address:
ip -brief address
From your computer:
ssh user@your_server_ip
ssh shows the server's key fingerprint on the first connection. To compare it, print the fingerprint on the server with ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub. More in how to SSH into a server.
If the Connection Fails
- Connection refused: nothing listens on that port, or the port is wrong. See SSH connection refused.
- Timed out: a firewall drops the packets, or the address is wrong.
- Permission denied: the password or key is not accepted. See Permission denied (publickey).
Next Steps
- Use keys: create a key pair as described in how to generate SSH keys and copy it to the server.
- Turn off passwords: follow disable SSH password authentication once key login works.
- Block root logins: see how to disable root login over SSH.
- Move the port if you want: it reduces log noise; it is not a security measure by itself.
Turn SSH Off Again
Do this only from the console, never from an SSH session you still need:
sudo systemctl disable --now ssh.socket ssh
This stops and disables both the socket and the service, so SSH does not come back at the next boot.