When connecting to an Ubuntu 10.04 LTS server via SSH from macOS, the default configuration automatically terminates inactive sessions after a few minutes. While this is a security best practice, it can disrupt workflow when working on long-running tasks or debugging sessions.
The primary solution involves modifying the SSH daemon configuration on your Ubuntu server. Edit the /etc/ssh/sshd_config
file:
# Open the configuration file sudo nano /etc/ssh/sshd_config # Add or modify these parameters ClientAliveInterval 300 ClientAliveCountMax 3 TCPKeepAlive yes
Parameters explanation:
ClientAliveInterval
: Sets timeout in seconds (300 = 5 minutes)ClientAliveCountMax
: Number of check attempts before disconnectTCPKeepAlive
: Maintains TCP connection state
For temporary solutions or when you don't have server access, configure your local SSH client:
# ~/.ssh/config or command line option Host ubuntu-server HostName your.server.ip User yourusername ServerAliveInterval 60 ServerAliveCountMax 5
After modifying server configuration, restart the SSH service:
sudo service ssh restart
To test the connection stability:
# Start a new SSH session ssh -v user@server # Monitor connection in another terminal sudo tcpdump -i any port 22
For persistent sessions regardless of connection stability:
# Install tmux if needed sudo apt-get install tmux # Start a named session tmux new -s persistent_work # Detach with Ctrl+B followed by D # Reattach later with: tmux attach -t persistent_work
- Check system logs:
tail -f /var/log/auth.log
- Verify firewall settings aren't dropping connections
- Test with different network configurations
Working with Ubuntu servers via SSH, many developers encounter the annoying automatic logout after periods of inactivity. While this is a security feature, it disrupts workflow when you need persistent connections for debugging or long-running processes.
The primary solution involves modifying the SSH server configuration. Edit the /etc/ssh/sshd_config
file:
# Open the config file with sudo privileges sudo nano /etc/ssh/sshd_config # Add or modify these parameters: ClientAliveInterval 300 ClientAliveCountMax 3 # Save changes and restart SSH sudo service ssh restart
For temporary solutions when you don't have server access:
# On your Mac, add this to ~/.ssh/config Host * ServerAliveInterval 60 TCPKeepAlive yes
Ubuntu also has system-wide timeout settings that might affect SSH:
# Check current settings cat /etc/profile | grep TMOUT # To disable completely sudo echo "unset TMOUT" >> /etc/profile source /etc/profile
When you can't modify server settings, GNU Screen offers a workaround:
# Install screen if needed sudo apt-get install screen # Start a new screen session screen -S persistent_session # Detach with Ctrl+A then D # Reattach later with: screen -r persistent_session
Remember that disabling timeout reduces security. Consider implementing:
- Stronger authentication methods
- IP-based restrictions
- Activity monitoring