# Can't SSH Into Your xCloud Server? Fix Timeouts and Denied Logins

> Fix 'Connection timed out', 'Connection refused' and 'Permission denied (publickey)' when you SSH into an xCloud server: port, firewall, Fail2Ban and keys.

If you can't SSH into your xCloud server, the error tells you where to look. **Connection timed out** means your connection never reached SSH: a firewall, a Fail2Ban ban or a wrong address. **Connection refused** usually means a wrong port. **Permission denied (publickey)** means you reached the server but the key you offered is not on that user. This guide shows how to tell which one you have, fix it from the [xCloud](/) dashboard first, then check it over SSH.

## Find your error first

Run SSH with `-v` from your computer. Use your own user, server IP and port:

```bash
ssh -v YOUR_SUDO_USER@SERVER_IP -p 22
```

Match the last lines to a row below.

| What you see | What it means | Go to |
|---|---|---|
| `ssh: connect to host SERVER_IP port 22: Connection timed out` | Nothing answered. A firewall drops the connection, your IP address is banned, the IP address is wrong, or the server is off | [Check the server is up](#step-1-check-the-server-is-connected), then [the firewall](#step-2-check-the-firewall-allows-your-ssh-port) and [Fail2Ban](#step-3-check-whether-fail2ban-banned-your-ip-address) |
| `ssh: connect to host SERVER_IP port 2222: Connection refused` | The server answered, but nothing listens on that port | [Use the right SSH port](#step-4-use-the-right-ssh-port) |
| `Permission denied (publickey).` | SSH works. The key you offered is not on this user | [Add your key to the sudo user](#step-5-add-your-ssh-key-to-the-sudo-user) |

A `Permission denied (publickey)` run looks like this. The line `Authentications that can continue: publickey` shows that this user can log in with a key only:

```
debug1: Connecting to SERVER_IP [SERVER_IP] port 22.
debug1: Connection established.
debug1: Authenticating to SERVER_IP:22 as 'xcloud'
debug1: Authentications that can continue: publickey
debug1: Offering public key: /home/you/.ssh/id_ed25519 ED25519 SHA256:... explicit
debug1: Authentications that can continue: publickey
xcloud@SERVER_IP: Permission denied (publickey).
```

**Why a password doesn't work here:** root and sudo users can log in with an SSH key only. A site user logs in with a key or a password, depending on what you set under Site → Access Data → SSH/sFTP. As root or a sudo user you log in with a key, and you type the sudo password only when you run a command with `sudo`. See [sudo users and site users in xCloud](/docs/usudo-users-and-site-users-in-xcloud/).

## Step 1: Check the server is connected

Open the server in xCloud and look at the badge next to its name.

- **Connected:** xCloud reached the server on its last check, so the server is up. The problem is most likely between your computer and the server. Continue with Step 2.
- **Disconnected:** xCloud can't reach it either. The server may be off, or a firewall may block xCloud too. Follow [Server Disconnected: are my sites down, and what can I fix myself](/docs/server-gets-disconnected/) first.

When the server is **Connected**, you can still get in while your own SSH is blocked. Click **Open Terminal** at the top of the server page. A web terminal opens in your browser as root, and you can run every server command in this guide there.

![Click 'Open Terminal' on the xCloud server page to get in from the browser](/_landing/docs/troubleshoot-ssh-connection-issues-in-xcloud-image-1.png)

The team owner can always open it. A team Admin or Server Admin also needs the root terminal permission, which xCloud never gives automatically: it has to be ticked for them by hand. The button doesn't show on a white-label dashboard. See [how to access the web terminal](/docs/access-web-terminal-in-xcloud/).

## Step 2: Check the firewall allows your SSH port

Go to **Security → Firewall Management** on the server. A new server has an **SSH** rule for port 22 that allows every IP address, plus **HTTP** (80) and **HTTPS** (443).

![The SSH rule for port 22 in Security → Firewall Management](/_landing/docs/troubleshoot-ssh-connection-issues-in-xcloud-image-2.png)

Check three things:

1. **The SSH rule exists and is active.** If you deleted it (for example with [SSH Lockdown](/docs/how-to-configure-ssh-lockdown/)), only xCloud's IP addresses and the addresses you allowed can connect.
2. **The IP Address column includes you.** A rule that lists IP addresses allows only those. If your home or office IP address changed, add a rule for the new one.
3. **The port matches your SSH port.** If you moved SSH to another port, the rule must allow that port.

To allow your own address, click **Add New Rule**, enter a **Name** (for example "SSH office"), your SSH port in **Port**, your public IP address in **IP Address (Optional)**, choose **TCP** and **Allow**, then click **Add Rule**. Leave xCloud's own rules in place, as explained in [lock down your server without breaking xCloud](/docs/lock-down-your-server-without-breaking-xcloud/). For more on rules, see [how to configure Firewall Management](/docs/how-to-configure-firewall-management-in-xcloud/).

Also check your provider's cloud firewall (for example a Vultr firewall group or a DigitalOcean cloud firewall). It sits in front of the server, and xCloud can't see or change it.

## Step 3: Check whether Fail2Ban banned your IP address

Fail2Ban runs on every xCloud server and blocks an IP address after repeated failed SSH logins. A script or SSH client that keeps trying a wrong key can get your own address banned. On a new xCloud server we checked (Ubuntu 24.04), the defaults were 5 failed attempts within 10 minutes, then a 10-minute ban.

1. On the same **Firewall Management** page, scroll to **Fail2Ban Management** and click **Fetch Now**. xCloud reads the list from the server.
2. Find your public IP address in **Banned IP Addresses**. If the entry ends with `sshd`, it was banned for failed SSH logins.
3. Click the delete icon in the **Action** column to unban it.

![An IP address banned for failed SSH logins, with its unban icon under Fail2Ban Management](/_landing/docs/troubleshoot-ssh-connection-issues-in-xcloud-image-3.png)

Fix the cause before you try again, or you'll be banned again: usually a wrong key (Step 5) or a wrong user name. To stop your own fixed IP address from ever being banned, add it to Fail2Ban's ignore list as shown in [Fail2Ban in xCloud](/docs/fail2ban-in-xcloud-enhancing-server-security-with-ease/).

## Step 4: Use the right SSH port

xCloud servers use port 22 unless you changed it. The port xCloud uses is under **Others → Connection Settings → SSH Port**.

![The SSH Port field in Connection Settings on the server's Others page](/_landing/docs/troubleshoot-ssh-connection-issues-in-xcloud-image-4.png)

This field tells xCloud which port to connect on. Saving it does not change the port on the server. If you changed the port on the server, connect with that port (`ssh -p 2222 ...`), make sure a firewall rule allows it, and set the same number here. The full steps are in [how to update the SSH port in xCloud](/docs/how-to-update-ssh-port-in-xcloud/).

## Step 5: Add your SSH key to the sudo user

`Permission denied (publickey)` means the key your computer offered is not on the user you named. Go to **Management → Sudo Users** on the server. The **SSH Keys** column shows how many keys each user has. A user with **0** keys can't log in over SSH at all.

![The SSH Keys count and the edit icon for a sudo user in Management → Sudo Users](/_landing/docs/troubleshoot-ssh-connection-issues-in-xcloud-image-5.png)

1. Click the pencil icon next to the user you log in as. Editing a sudo user needs [two-factor authentication](/docs/two-factor-authentication-set-it-up-and-recover-access-if-you-lose-your-device/) on your account.
2. Tick the SSH key that matches the key on your computer, or click **Add SSH Key** to paste a new public key.
3. Click **Save** and wait for **Status** to show **provisioned**.

Not sure which key is yours? Compare fingerprints, as shown in [how to add and remove SSH keys in xCloud](/docs/how-to-generate-and-add-ssh-keys-in-xcloud/). Also check that you log in as the right user: a site user can only use the keys added to that site under **Site → Access Data → SSH/sFTP**, see [how to configure SFTP access](/docs/how-to-configure-sftp-access/).

## Check it from the server

Run these in the web terminal, or over SSH once you're in. We ran these commands on a new xCloud server with Ubuntu 24.04; your PIDs and rules will differ.

Is SSH running, and on which port?

```bash
sudo ss -tlnp | grep sshd
```

```
LISTEN 0  4096  0.0.0.0:22  0.0.0.0:*  users:(("sshd",pid=652,fd=3),...)
LISTEN 0  4096     [::]:22     [::]:*  users:(("sshd",pid=652,fd=4),...)
```

Does the firewall on the server allow that port?

```bash
sudo ufw status
```

```
Status: active

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere
80                         ALLOW       Anywhere
443                        ALLOW       Anywhere
443/udp                    ALLOW       Anywhere
```

Is your IP address banned?

```bash
sudo fail2ban-client status sshd
```

```
Status for the jail: sshd
|- Filter
|  |- Currently failed: 0
|  `- Total failed: 0
`- Actions
   |- Currently banned: 1
   `- Banned IP list: 203.0.113.10
```

Unban it from the command line with `sudo fail2ban-client set sshd unbanip 203.0.113.10`, using your own IP address.

Does SSH accept keys only for root and sudo users?

```bash
sudo sshd -T | grep -Ei '^(port|passwordauthentication|permitrootlogin) '
```

```
port 22
permitrootlogin without-password
passwordauthentication no
```

`without-password` means root can log in with a key, never with a password. These lines show the server-wide setting; a site user set to log in with a password has its own rule in the SSH config. Don't turn password login back on to get around a key problem; add the key instead.

## If you still can't get in

- **The server shows Disconnected and the web terminal doesn't help:** use your provider's web console, then follow [Server Disconnected](/docs/server-gets-disconnected/).
- **The server's IP address changed** (for example after a rebuild): see [what to do when your server's IP address changes](/docs/server-ip-address-change-xcloud/).
- **You only reach the server over a private network:** see [Tailscale SSH with your xCloud server](/docs/use-tailscale-ssh-with-xcloud-server/).

## Frequently asked questions

### Why does SSH say Permission denied (publickey) on my xCloud server?

You reached the server, but none of the keys your computer offered is on the user you logged in as. Root and sudo users can log in with an SSH key only, so a password never works for them. Add your public key to that sudo user under Management → Sudo Users, or log in as a user that already has it.

### Can I log in to my xCloud server with a password over SSH?

Not as root or a sudo user: they can log in with an SSH key only. A site user logs in with a key or a password, depending on what you set under Site → Access Data → SSH/sFTP. The sudo password is what you type when you run a command with sudo, not a login password.

### How do I know if Fail2Ban banned my IP address?

Open the server, go to Security → Firewall Management and click Fetch Now under Fail2Ban Management. If your public IP address is in the Banned IP Addresses list, click the delete icon next to it to unban it.

### Can I still reach my server if SSH from my computer is blocked?

Often, yes: if the server is Connected and your role includes the web terminal, click Open Terminal on the server page to get a web terminal in your browser, then fix the firewall, Fail2Ban or key from there. If the server shows Disconnected, xCloud can't reach it either, so use your provider's console.

Still stuck? Contact [xCloud support](/docs/access-built-in-support-portal-in-xcloud/) with the last lines of your `ssh -v` output.
