powershell 7 randomly drops ssh connections after exactly 3 minutes
Posted by Sroni4967@reddit | sysadmin | View on Reddit | 10 comments
upgraded from powershell 5 to 7.4.6 last week and now ssh sessions to linux boxes just die at the 3 minute mark every time. happens with openssh client 9.5 on windows 11 22h2, but only when launched from pwsh not cmd.
Sroni4967@reddit (OP)
sounds like a timeout somewhere, check your ssh client config for ServerAliveInterval
nailzy@reddit
Why the hell are you replying to your own post with advice to yourself??
dedjedi@reddit
"randomly"
"every time"
Given your stunning grasp of the English language, I'm going to go out on a limb and guess that there is far more Happening Here than you've described.
CrumpetNinja@reddit
I'm pretty sure OP is a bot account. It's only 3 days old and it's been commenting / posting non-stop ever since.
AussieTerror@reddit
Agreed. That pattern looks less like a person and more like a freshly deployed Service desk AI agent learning in the wild.
Sroni4967@reddit (OP)
check your ssh keepalive settings, sounds like something is timing out the connection
omglazrgunpewpew@reddit
If it truly is exactly at 3 min, then that's the key. Smells like a timer somewhere
Best first test would be to run this from both pwsh and cmd and then compare the last lines before disconnect:
If
ssh -vvvshows an idle-style timeout or maybe a broken pipe/reset/whatever, confirm withIf keepalives stop the drop, it’s likely a firewall/NAT/session idle timeout. If it still drops at exactly 3 min, try checking these:
pwsh may not be launching the same ssh.exe as cmd
pwsh -NoProfile Get-Command ssh -All where.exe ssh $env:PATH -split ';'
Run the SSH test inside the new shell
A $PROFILE script could define an ssh function, alter env vars, set TERM, set proxy vars, or start SSH through something else.
Test-Path $PROFILE notepad $PROFILE Get-Alias ssh -ErrorAction SilentlyContinue Get-Command ssh
Test the combos
cmd + ssh powershell 5.1 + ssh pwsh -NoProfile + ssh pwsh inside Windows Terminal pwsh inside plain conhost
You say PS 7.4.6 on Win 11 22H2 which others have commented current PS is 7.6.1, and MS announced 7.6 as the current LTS in March 2026. Upgrading is worth doing, but I’d still isolate profile/path first because “only launched from pwsh” is kinda a strong clue.
Curious201@reddit
the “exactly 3 minutes” part makes me think timer or profile/config more than a normal ssh problem. i would test it in a clean pwsh session first with no profile loaded, then compare what command is actually being launched from pwsh versus cmd:
Get-Command ssh,$env:PATH, any aliases/functions, and whether your$PROFILEis setting something weird. also try runningssh -vvv user@hostfrom both cmd and pwsh and compare the last few lines before the disconnect. if it only happens from pwsh, i would also test Windows Terminal vs plain console host, and try a keepalive in~/.ssh/configlikeServerAliveInterval 30andServerAliveCountMax 3, not because it fixes the root cause, but because it tells you whether the session is just going idle or being killed from the client sidepoizone68@reddit
Do you use any keep alive parameter for your ssh connection?
Ghelderz@reddit
Why PowerShell 7 version 7.4.6 when the latest is 7.6.1?