DeveloperBreeze

How to Stop SSH From Timing Out

If your SSH session closes after a minute of inactivity, it’s usually caused by idle timeouts. You can fix this with keep-alive settings on both the server and client.

1. Server-Side Fix

Edit the SSH daemon config:

sudo nano /etc/ssh/sshd_config

Add these lines:

ClientAliveInterval 60
ClientAliveCountMax 3

This makes the server send a keep-alive packet every 60 seconds, allowing up to 3 missed replies before disconnecting.

Restart SSH:

sudo systemctl restart sshd

2. Client-Side Fix

On your local machine, edit or create:

nano ~/.ssh/config

Add:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

This ensures your SSH client pings the server regularly.


That’s it. With these changes, your SSH session will stay alive and won’t drop after just a minute.

Related Posts

More content you might like

Tutorial
bash

How to Check and Configure SSH Timeout Settings on Your Server

SSH timeout settings are vital for maintaining server security and managing resources efficiently. By setting appropriate timeout values, you can ensure that idle sessions are automatically closed, reducing the risk of unauthorized access. These settings also help conserve server resources by freeing up connections that are no longer active.

Aug 19, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!