# Disable SSH Timeout on EC2

The automatic logout on EC2 running Debian 12 is typically due to the SSH session timing out or a terminal session timeout. You can disable these timeouts by adjusting the SSH and shell settings. Here are the steps you can follow:

#### 1. Disable SSH Timeout

To prevent SSH from timing out, you can modify the SSH server configuration:

Open the SSH server configuration file:

```sh
sudo nano /etc/ssh/sshd_config
```

Find and set the following parameters (if they are not present, add them):

```sh
ClientAliveInterval 120
ClientAliveCountMax 720
```

`ClientAliveInterval 120` sets the interval (in seconds) after which the server will send a message to the client requesting a response to keep the connection alive. In this case, it is set to 120 seconds.

`ClientAliveCountMax 720` sets the number of client alive messages that can be sent without receiving any messages back from the client. In this case, it is set to 720. Combined with the `ClientAliveInterval`, this allows for a 24-hour (120 seconds \* 720) timeout.

Save the file and exit the editor (Ctrl+O, Enter to save, Ctrl+X to exit).

Restart the SSH service to apply the changes:

```sh
sudo systemctl restart sshd
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.jinshupeethambaran.com/articles/aws/disable-ssh-timeout-on-ec2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
