October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Keep Your SSH Session Alive

Use OpenSSH ServerAliveInterval and ServerAliveCountMax to keep idle client sessions active, or configure ClientAliveInterval and ClientAliveCountMax on the server. This guide explains timing, TCP differences, validation, and troubleshooting.
Length8 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To keep an SSH session from being dropped while it is idle, configure the OpenSSH client to send encrypted probes: ServerAliveInterval sets the idle interval and ServerAliveCountMax sets how many unanswered probes are tolerated. For a server you administer, the corresponding settings are ClientAliveInterval and ClientAliveCountMax. A one-time client command is:

ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 user@host

For a permanent client setting, put the directives in ~/.ssh/config. Server settings belong in /etc/ssh/sshd_config, followed by syntax validation and a daemon reload. These SSH-level keepalives are different from TCP keepalives and travel inside the encrypted SSH channel.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What an SSH keepalive actually does

An idle SSH connection can be removed by a firewall, NAT gateway, VPN, load balancer, sleeping laptop, changing network, or a genuinely unreachable endpoint. SSH keepalives periodically create traffic so an otherwise quiet connection is checked instead of remaining completely idle.

OpenSSH has two directional configurations. The client-side ServerAlive* options make your SSH client send an encrypted request after a period with no incoming server data. The server-side ClientAlive* options make sshd send a request when it has received no client data. A probe is not a promise that the remote host will remain available: unanswered probes eventually close the connection, which prevents a dead session from appearing usable forever.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

These messages are SSH protocol traffic carried through the encrypted channel. OpenSSH’s server documentation states that client-alive messages are sent through the encrypted channel and therefore are not spoofable. They are not the same mechanism as TCP keepalives.

Configure the OpenSSH client

Understand the two client options

Option Meaning OpenSSH default
ServerAliveInterval Seconds of inactivity before the client sends an encrypted request to the server. A value of 0 disables these requests. 0
ServerAliveCountMax Number of unanswered server-alive requests the client tolerates before disconnecting. 3

The interval is not a total session timeout. It applies when no server data has arrived. With an interval of 60 seconds, an active transfer or command that is already producing server traffic does not need an additional idle probe at that moment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make the setting permanent for your user

  1. Create or open ~/.ssh/config on the computer from which you run SSH.
  2. Add a host block. To apply it to every destination, use:
Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

Use a narrower block such as Host production.example when only one destination needs the policy. Keep the options in the client configuration file; placing them in /etc/ssh/sshd_config will not change how your local client behaves.

Apply a setting to one connection

For a temporary test or a single maintenance session, pass the options on the command line:

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 user@host

This is useful when you cannot or do not want to alter your user configuration. It also lets you compare behavior with and without keepalives before choosing a permanent value.

How long before a failed connection is declared dead?

The approximate detection window is the interval multiplied by the number of unanswered probes. OpenSSH’s documented example uses ServerAliveInterval 15 with the default count of three; an unresponsive server is disconnected after approximately 45 seconds. The actual experience can vary with scheduling and network timing, so treat the product as an operational approximation rather than a precise stopwatch.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure the OpenSSH server

Understand the server-side pair

Option Meaning
ClientAliveInterval Seconds after receiving no client data before sshd sends a request through the encrypted channel.
ClientAliveCountMax Number of unanswered client-alive requests allowed before the server disconnects the client.

These settings affect connections accepted by that server. They do not replace a user’s client-side configuration, and they do not change the idle policies enforced by an intermediate firewall, VPN, NAT device, or load balancer.

Change the server configuration safely

  1. Back up the current /etc/ssh/sshd_config and edit it with administrative privileges.
  2. Add or adjust the directives, for example:
ClientAliveInterval 60
ClientAliveCountMax 3
  1. Validate the complete configuration before applying it with sshd -t. A syntax error must be fixed before reloading; otherwise you risk leaving the daemon unable to accept the intended configuration.
  2. Use the operating system’s service manager to reload the SSH daemon. On a systemd installation the service may be named sshd or ssh, so use the name supplied by that operating system rather than assuming one universal command.
  3. Start a new SSH connection and test it. Existing sessions may not inherit changed daemon settings.

Server-side keepalives are especially useful when you operate the host and want a consistent policy for many clients. Set them with awareness of the number of concurrent sessions: a short interval and high count can create more probe traffic and retain dead sessions longer.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

SSH keepalives versus TCP keepalives

ServerAliveInterval, ServerAliveCountMax, ClientAliveInterval, and ClientAliveCountMax operate at the SSH protocol layer. Their requests are encrypted SSH messages, so an intermediary cannot forge a valid response merely by seeing the packet.

TCPKeepAlive is a separate TCP mechanism. It can help the operating system detect a dead peer, but it can respond differently to transient route failures and does not let you choose an SSH-level probe schedule. The Debian server documentation describes TCPKeepAlive as enabled by default in that package documentation and warns that disabling it can leave ghost sessions consuming resources. Do not treat TCP keepalives as a substitute for selecting an SSH probe interval.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In practice, SSH-level probes are the setting to tune when your goal is surviving an idle timeout imposed somewhere between the two endpoints. TCP keepalives remain a separate transport behavior with its own operating-system and network characteristics.

Choose an interval and count deliberately

Start with the timeout you need to beat

Identify the shortest idle timeout in the path: a corporate firewall, home router, cloud load balancer, VPN concentrator, or other middlebox. Choose an SSH interval shorter than that timeout so traffic is seen before the connection is classified as idle. If the timeout is unknown, begin with a moderate value such as 60 seconds and observe whether the connection remains stable, then adjust to the actual policy rather than assuming every network has the same limit.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Balance resilience against failure-detection speed

The count determines how much silence you accept after a probe. Increasing ServerAliveCountMax or ClientAliveCountMax allows brief network interruptions to recover without immediately terminating the session, but it lengthens the period during which an unreachable endpoint appears connected. Decreasing the count shortens failure detection and releases resources sooner.

For example, an interval of 60 seconds and a count of three gives an approximate three-minute unanswered-probe window. An interval of 15 seconds and a count of three gives approximately 45 seconds, the timing described in the OpenSSH client documentation. These calculations are planning tools, not universal vendor recommendations; choose values according to the cost of a false disconnect versus the cost of waiting for a dead session to be recognized.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Consider the workload

  • Interactive shell work benefits from probes frequent enough to cross the network’s idle threshold without generating needless traffic.
  • Long-running commands that produce no output still need the same idle policy if a middlebox may expire the connection.
  • Very large fleets should avoid unnecessarily aggressive intervals on every account; multiply probe frequency by concurrent sessions when estimating operational load.
  • If the endpoint is expected to be unavailable for an extended period, a keepalive cannot preserve a route that no longer exists. It can only detect the condition according to the chosen interval and count.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Verify what the client is really using

Configuration files can contain multiple host blocks, and a command-line option can override a file value. Ask OpenSSH to print the effective configuration for a destination:

ssh -G host | grep -i alive

Check that the output contains the intended serveraliveinterval and serveralivecountmax values. Run the command with the same host alias you use for the real connection; testing a different alias can select a different Host block.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

When diagnosing the server side, inspect the active /etc/ssh/sshd_config, run sshd -t, reload through the service manager, and then establish a fresh connection. A successful syntax check only proves that the file parses; it does not prove that a firewall or VPN will permit the probes.

Troubleshoot disconnects that continue

The client setting has no effect

  • Confirm the directives are in ~/.ssh/config, not only in the server file.
  • Use ssh -G host | grep -i alive to verify the effective values for the exact host alias.
  • Check spelling and capitalization. OpenSSH option names are normally written exactly as documented, such as ServerAliveInterval.
  • Try the one-time -o command-line form to separate a configuration-file problem from a network problem.

The server setting has no effect

  • Make sure you edited /etc/ssh/sshd_config on the server that actually accepts the connection.
  • Run sshd -t before reloading and correct every reported error.
  • Reload the daemon with the host operating system’s service manager, then open a new session.
  • Check server logs if the daemon rejects the configuration or closes sessions unexpectedly.

The session still drops at a predictable idle time

A middlebox may have an idle policy shorter than your interval, or it may ignore or mishandle the traffic. Reduce the SSH interval so a probe occurs before that policy expires. If the network has brief interruptions, increase the tolerated count instead of making the interval extremely short. Verify VPN behavior and firewall or NAT idle settings; SSH cannot override a device that deliberately tears down the route.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The laptop sleeps or changes networks

When the client sleeps, loses connectivity, or switches between Wi-Fi and another network, probes cannot receive timely replies. Keepalives will eventually identify the connection as unresponsive, but they cannot resume a TCP path that changed underneath it. Inspect the client sleep behavior and network transitions, then reconnect after connectivity is restored.

Sessions remain as ghosts on the server

If dead sessions consume server resources, do not disable every liveness mechanism indiscriminately. The Debian server documentation warns that disabling TCPKeepAlive can leave ghost sessions consuming resources. Instead, choose an SSH interval and count that detect failure within an acceptable window, and keep the server’s resource limits and logging under review.

A practical rollout checklist

  1. Decide whether the requirement is per-client, server-wide, or both.
  2. Identify the shortest relevant idle timeout in the firewall, NAT, VPN, or load-balancer path.
  3. Set a client interval below that timeout, then choose a count based on how long brief outages may last.
  4. For a client, test with ssh -o ServerAliveInterval=... before editing ~/.ssh/config.
  5. For a server, edit /etc/ssh/sshd_config, validate with sshd -t, reload through the service manager, and open a new session.
  6. Confirm effective client values with ssh -G host | grep -i alive.
  7. If drops continue, investigate middlebox policies, VPN behavior, server logs, sleep, and network changes rather than increasing keepalive values blindly.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.