1

Sometimes when I'm on a sketchy internet connection like an airplane, my ssh session drops suddenly. When this happens, I want the sshd server to automatically kill the session after a few seconds, to save money on EC2 instance time. Usually this works okay, but sometimes the session can stay open for over an hour. How can I change the timeout to a few minutes?

Here are my settings:

# sshd -T | grep -vE '^ciphers|^macs|^kexalgorithms|^hostbasedacceptedkeytypes|^hostkeyalgorithms|^pubkeyacceptedkeytypes|^listenaddress'
port 22
addressfamily any
usepam yes
logingracetime 120
x11displayoffset 10
x11maxdisplays 1000
maxauthtries 6
maxsessions 10
clientaliveinterval 0
clientalivecountmax 3
streamlocalbindmask 0177
permitrootlogin yes
ignorerhosts yes
ignoreuserknownhosts no
hostbasedauthentication no
hostbasedusesnamefrompacketonly no
pubkeyauthentication yes
kerberosauthentication no
kerberosorlocalpasswd yes
kerberosticketcleanup yes
gssapiauthentication yes
gssapicleanupcredentials no
gssapikeyexchange no
gssapistrictacceptorcheck yes
gssapistorecredentialsonrekey no
gssapikexalgorithms gss-gex-sha1-,gss-group1-sha1-,gss-group14-sha1-
passwordauthentication no
kbdinteractiveauthentication no
challengeresponseauthentication no
printmotd yes
printlastlog yes
x11forwarding yes
x11uselocalhost yes
permittty yes
permituserrc yes
strictmodes yes
tcpkeepalive yes
permitemptypasswords no
permituserenvironment no
compression yes
gatewayports no
showpatchlevel no
usedns yes
allowtcpforwarding yes
allowagentforwarding yes
disableforwarding no
allowstreamlocalforwarding yes
streamlocalbindunlink no
useprivilegeseparation sandbox
kerberosusekuserok yes
gssapienablek5users no
exposeauthenticationmethods never
fingerprinthash SHA256
pidfile /var/run/sshd.pid
xauthlocation /usr/bin/xauth
banner none
forcecommand none
chrootdirectory none
trustedusercakeys none
revokedkeys none
authorizedprincipalsfile none
versionaddendum none
authorizedkeyscommand /usr/bin/timeout 5s /opt/aws/bin/curl_authorized_keys %u %f
authorizedkeyscommanduser ec2-instance-connect
authorizedprincipalscommand none
authorizedprincipalscommanduser none
hostkeyagent none
loglevel INFO
syslogfacility AUTHPRIV
authorizedkeysfile .ssh/authorized_keys
hostkey /etc/ssh/ssh_host_rsa_key
hostkey /etc/ssh/ssh_host_ecdsa_key
hostkey /etc/ssh/ssh_host_ed25519_key
acceptenv LANG
acceptenv LC_CTYPE
acceptenv LC_NUMERIC
acceptenv LC_TIME
acceptenv LC_COLLATE
acceptenv LC_MONETARY
acceptenv LC_MESSAGES
acceptenv LC_PAPER
acceptenv LC_NAME
acceptenv LC_ADDRESS
acceptenv LC_TELEPHONE
acceptenv LC_MEASUREMENT
acceptenv LC_IDENTIFICATION
acceptenv LC_ALL
acceptenv LANGUAGE
acceptenv XMODIFIERS
authenticationmethods any
subsystem sftp /usr/libexec/openssh/sftp-server
maxstartups 10:30:100
permittunnel no
ipqos lowdelay throughput
rekeylimit 0 0
permitopen any
3
  • setting ClientAliveInterval 5 and ClientAliveCountMax 3 in the server's config will kill the unresponsive client connections after 15 seconds.
    – user313992
    May 30, 2019 at 21:58
  • 1
    Can ya add the output of sshd -T | grep -vE '^ciphers|^macs|^kexalgorithms|^hostbasedacceptedkeytypes|^hostkeyalgorithms|^pubkeyacceptedkeytypes|^listenaddress' from your server, to your question? This'll expose what settings your server is using (minus fluf) such as states for ClientAliveCountMax and ClientAliveInterval... which hint, man --pager='less -p ClientAliveCountMax' sshd_config and following sections I believe will be most relevant to what it is I think you want.
    – S0AndS0
    May 30, 2019 at 22:00
  • I've added that info to the question
    – Elliott B
    Jun 2, 2019 at 1:41

0

You must log in to answer this question.

Browse other questions tagged .