# Keeping an SSH connection alive

> Stop idle SSH sessions dropping by setting keepalive options in your SSH client on Windows, macOS or Linux.

Source: https://helpcenter.ruachost.com/getting-started/your-account/keep-ssh-connection-alive/

When working on your server through SSH, you may sometimes experience dropped or unresponsive connections. This usually happens because firewalls or network devices close idle connections after a period of inactivity. To prevent this, you can configure your SSH client to send periodic keepalive signals.

## Why Connections Drop

- Some firewalls automatically close idle sessions.
- Network devices may time out long-lived connections.
- By default, SSH does not always send keepalive packets.

The result is that your SSH session may disconnect unexpectedly if left idle.

## Solutions by Operating System

### Windows (PuTTY)

If you use **PuTTY** to connect to your Ruachost server:

1. Open **PuTTY**.
2. Load your saved session.
3. In the left-hand **Category** pane, click **Connection**.
4. Under **Sending of null packets to keep session active**, set **Seconds between keepalives** to `240`.

   - This sends a keepalive packet every 4 minutes.
5. Go back to **Session**, click **Save** to update your profile.
6. Reconnect and monitor stability.

   - If the connection still drops, try lowering the interval (e.g., 120 seconds).

### Linux and macOS (OpenSSH Client)

On Linux and macOS, you can configure keepalive settings in your SSH client configuration file.\
     Open or create the SSH config file:

```bash
nano ~/.ssh/config
```

```bash
Host yourdomain
    Hostname yourdomain.com
    Port 22
    User yourusername
    ServerAliveInterval 240
    ServerAliveCountMax 2
```

- - Replace `yourdomain.com` with your domain or server IP.
  - Replace `yourusername` with your Ruachost account username.
  - If your server uses a custom SSH port (e.g., 7822), update the `Port` value.
- Save and exit.
- Connect using:

  ```bash
  yourdomain
  ```

  With this configuration:

  - The client sends a keepalive packet every 240 seconds.
  - If no response is received after 2 attempts, the connection closes gracefully.
