Skip to content

about Networks!

Sketches of IP, Routing, Internet, Security and Life!

  • Who am I?
  • networks in Persian
  • Let’s talk :)

Tag: session

HowTo : (Linux) Keep SSH session alive and run scripts on login/logout

Some task which I always do when owning a private Linux machine (Debian, bash).

Keeping SSH session open:
With the setting below, my SSH client will send a keepalive to the SSH server every 30 seconds to keep the session up, and prevent session time-out

mmoghaddas@debian:~$ egrep 'Host|Alive' /etc/ssh/ssh_config
Host *
ServerAliveInterval 30

Obviously you can also set similar settings on SSH server:

moghaddas@debian:~$ egrep Alive /etc/ssh/sshd_config 
ClientAliveInterval 60
ClientAliveCountMax 0
TCPKeepAlive yes

Run scripts immediately on login:
Just create a script and put inside /etc/profile.d/SCRIPT.sh

Run scripts immediately on logout:
Easily by adding everything in .bash_logout For example creating different scripts, and referencing them inside this file.

Run scripts on session timeout:
Well, this is actually not 100% on timeout, but when a session times out and then someone logs in. You can create a script, then tail the auth.log (if available) and awk for Timeout, then run the script:

moghaddas@debian:~$ cat /etc/profile.d/
bash_completion.sh SCRIPT.sh
moghaddas@debian:~$ cat /etc/profile.d/SCRIPT.sh
tail /var/log/auth.log | awk '/Timeout, client not responding/ { system("sh TIMEOUT.sh") }'
Share this!
Author Mo MoghaddasPosted on July 3, 2015August 12, 2016Categories Configuration, LinuxTags alive, awk, bash, howto, keepalive, login, logout, script, session, shell, ssh, timeoutLeave a comment on HowTo : (Linux) Keep SSH session alive and run scripts on login/logout

Recent Posts

  • Good read: Do you block ICMP at all places in Network?
  • Good read: Money well spent??
  • Why SSL Inspection matters?
  • Do you need an IT Certification?
  • Enterprise Core Routing Design Models with BGP
  • Check Point CCSE Notes
  • Some basic EEM applets
  • Network Design Project Initial Questions
  • Check Point CCSA Notes
  • DRBD with Cluster File System on Debian Jessie
  • Cisco ACI – 2 – Provisioning a fabric
  • Determine Checkpoint model from CLI
  • A brief introduction to FabricPath
  • Cisco ACI – 1 – High level architecture overview
  • Typical access-list on edge router
  • BGP – Controlling the Entry Point (HLD)
  • Advanced Cisco BGP features: Selective Next-hop
  • Advanced Cisco BGP features: NSF
  • Advanced Cisco BGP features: BFD
  • Internet routing table and damping on JunOS

Categories

  • CCDE
  • CCIE
    • CCIE R&S
    • CCIE Security
  • Configuration
    • Juniper
  • Data Center
  • Design
  • Good read
  • Linux
  • Network Security
  • Other things
  • Routing
    • BGP
    • MPLS
    • OSPF
  • Switching

Most used:

  • ACI
  • AS-path
  • attribute
  • book notes
  • CEF
  • checkpoint
  • Check Point
  • cloud
  • DCI
  • Etherchannel
  • fabric
  • FEC
  • filtering
  • firewall
  • forwarding
  • high-availability
  • howto
  • IGP
  • IPExpert
  • junos
  • LDP
  • load-balancing
  • load-sharing
  • logging
  • LSA
  • LSR
  • MED
  • MPLS-VPN
  • MPLS fundamentals
  • NAT
  • nexus
  • NSF
  • OSPF
  • policy
  • prefix-list
  • QoS
  • service-policy
  • shell
  • spanning-tree
  • SSO
  • switchport
  • terminal
  • VLAN
  • vPC
  • VRF
  • Who am I?
  • networks in Persian
  • Let’s talk :)
about Networks! Privacy Policy Proudly powered by WordPress