> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Fix "SSH Connection Refused" on Linux

> Fix "ssh: connect to host port 22: Connection refused": start the SSH service, use the right port, check sshd -t and firewall or Fail2ban rejects.

"Connection refused" means your computer reached the server, but nothing accepted the connection on that port. Usually the SSH service is stopped, SSH listens on a different port, or a firewall or Fail2ban rule rejects you. Log in through the VNC console, run `sudo systemctl status ssh` (Ubuntu/Debian) or `sudo systemctl status sshd` (AlmaLinux/Rocky), and check the port with `sudo ss -tlnp`.

```text theme={null}
ssh: connect to host 203.0.113.10 port 22: Connection refused
```

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 to 15 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux and Rocky Linux 9 / 10 | Console access, root or sudo |

## Before you start

* You can't use SSH to fix SSH. On a VPS, open the [VNC console](https://help.freakhosting.com/portals/vps-panel/how-to-enable-and-use-vnc-console-access.md) and log in there. On a dedicated server, [open a ticket](https://freakhosting.com/clientarea/submitticket.php) for KVM/IPMI access.
* Check the server is powered on and booted in the [VPS Panel](https://help.freakhosting.com/portals/vps-panel/how-to-start-stop-restart-and-power-off-your-vps.md). A server that is still starting refuses connections for a short time.
* Commands use `sudo`. As root, leave it out.

## Refused or timed out?

The wording tells you where to look:

| Message | Meaning |
| - | - |
| `Connection refused` | The server answered "no": no program on that port, or a rule that rejects. This page. |
| `Connection timed out` | No answer at all: network, firewall that drops, or the wrong IP. See [SSH connection timed out](https://help.freakhosting.com/portals/other/how-to-fix-ssh-connection-timed-out.md). |
| `Permission denied (publickey)` | SSH works; your login doesn't. See [Permission denied (publickey)](https://help.freakhosting.com/portals/other/how-to-fix-ssh-permission-denied-publickey.md). |

## Cause 1: The SSH service isn't running

Most common after a reboot, a package upgrade or an edit to `sshd_config` that contains an error.

**Check** (on the console):

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo systemctl status ssh
> ```
>
> Ubuntu 22.10 and later can start SSH through `ssh.socket`. Check that too: `sudo systemctl status ssh.socket`.

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo systemctl status sshd
> ```

`Active: inactive (dead)` or `failed` means SSH is off.

**Fix:** test the configuration first, then start the service.

```bash theme={null}
sudo sshd -t
```

No output means the configuration is valid. If it prints a line such as `/etc/ssh/sshd_config line 14: Bad configuration option: Prot`, fix that line, run `sshd -t` again, then start SSH:

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo systemctl enable --now ssh
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo systemctl enable --now sshd
> ```

If `systemctl` says the unit doesn't exist, the SSH server isn't installed. Install it with `sudo apt install openssh-server` (Ubuntu/Debian) or `sudo dnf install openssh-server` (AlmaLinux/Rocky).

## Cause 2: SSH listens on a different port

If you or a script [changed the SSH port](https://help.freakhosting.com/portals/other/how-to-change-the-ssh-port.md), port 22 refuses connections.

**Check** which ports SSH listens on:

```bash theme={null}
sudo ss -tlnp | grep -E 'sshd|systemd'
```

```text theme={null}
LISTEN 0  128   0.0.0.0:2222   0.0.0.0:*   users:(("sshd",pid=812,fd=3))
```

**Fix:** connect to the port shown:

```bash theme={null}
ssh -p 2222 alex@203.0.113.10
```

Also check that `ListenAddress` in `/etc/ssh/sshd_config` isn't set to `127.0.0.1` or an old IP. SSH then refuses connections on your public IP.

## Cause 3: A firewall or Fail2ban rule rejects you

A firewall (software that decides which connections reach your server) usually drops blocked traffic, which shows as a timeout. Rules that **reject** instead give "Connection refused". Fail2ban, depending on its ban action, can do either after several failed logins.

**Check:**

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo ufw status verbose
> sudo fail2ban-client status sshd
> ```
>
> Look for a `REJECT` or `DENY` rule on your SSH port, and for your own IP under `Banned IP list`.

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo firewall-cmd --list-all
> sudo fail2ban-client status sshd
> ```
>
> `ssh` (or your custom port) should appear under `services` or `ports`.

**Fix:** allow SSH (`sudo ufw allow OpenSSH`, or `sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload`) and unban your IP with `sudo fail2ban-client set sshd unbanip 198.51.100.25`. Find your public IP by searching "what is my IP" on your computer.

Also check our [Firewall panel](https://help.freakhosting.com/portals/firewall/firewall-panel-overview.md) if you use it, in case a rule there blocks the port.

## Cause 4: You're connecting to the wrong IP

A typo, an old IP or a domain that still points to a previous server sends you to a machine that doesn't run SSH. Compare the IP in your command with the one in the [VPS Panel](https://help.freakhosting.com/portals/vps-panel/a-tour-of-your-server-page.md), and connect by IP rather than by domain while you test.

## How to check it worked

From your computer:

```bash theme={null}
ssh -v alex@203.0.113.10
```

A working connection shows `debug1: Connection established.` followed by the login prompt.

## Frequently asked questions

### Why do I get "Connection refused" right after rebooting?

SSH starts near the end of the boot. Wait a minute and try again. If it still fails, the service didn't start: check it on the VNC console as in Cause 1.

### Does "Connection refused" mean my server is hacked or down?

No. It proves the server is up and reachable, because it answered. Only the SSH port refused you.

### SSH works from the console but not from outside. Why?

SSH runs, so the port or firewall is the problem. Compare `sudo ss -tlnp` with your firewall rules and with the port you use in your SSH command.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [SSH connection timed out](https://help.freakhosting.com/portals/other/how-to-fix-ssh-connection-timed-out.md)
>
> When the server doesn't answer at all.

> [card] [Locked out after a firewall change](https://help.freakhosting.com/portals/other/how-to-fix-locked-out-after-firewall-change.md)
>
> Undo a rule that blocks SSH.

> [card] [Manage services with systemctl](https://help.freakhosting.com/portals/other/how-to-manage-services-with-systemctl.md)
>
> Start, stop and enable services.

> [card] [Connect with SSH](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md)
>
> The basics of logging in.

***

> [!NOTE]
>
> **Checked against the official [OpenSSH sshd manual](https://man.openbsd.org/sshd) and [Ubuntu's OpenSSH server guide](https://ubuntu.com/server/docs/how-to/security/openssh-server/)** on 4 November 2026; the "Connection refused" message, `sshd -t` and `ss -tlnp` were tested on Ubuntu 24.04 LTS (OpenSSH 9.6). Service restarts and the AlmaLinux steps were not tested.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.