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.