Identifying Slow Login Issues
Slow login (5-30 seconds) is usually caused by:
- DNS reverse lookups
- GSSAPI authentication attempts
- Large ~/.ssh/authorized_keys file
- PAM module delays
- Resource constraints
Fix 1: Disable DNS Lookups
Edit /etc/ssh/sshd_config:
UseDNS noThen restart SSH:
sudo systemctl restart sshdThis is the most common fix, reducing login time from 10+ seconds to instant.
Fix 2: Disable GSSAPI Authentication
Add to /etc/ssh/sshd_config:
GSSAPIAuthentication noAlso on client side (~/.ssh/config or /etc/ssh/ssh_config):
GSSAPIAuthentication noFix 3: Check .bashrc or .profile Delays
Your shell startup files might have slow commands:
# Add debugging to ~/.bashrc
set -x
# At the end of ~/.bashrc
set +xThen login and watch for delays. Common culprits:
- Network commands (curl, wget)
- Large directory traversals
- Version control status checks
Fix 4: Reduce Authorized Keys Size
If you have many SSH keys in authorized_keys, consider removing unused ones or using Match Blocks in sshd_config.
Fix 5: Check PAM Modules
Comment out unnecessary PAM modules in /etc/pam.d/sshd:
# Example - disable unused modules
# auth optional pam_motd.so
# session optional pam_mail.soFix 6: Use ControlMaster for Multiple Sessions
Client-side ~/.ssh/config:
Host *
ControlMaster auto
ControlPath ~/.ssh/controlmasters/%r@%h:%p
ControlPersist 10mmkdir -p ~/.ssh/controlmastersThis reuses existing connections, eliminating login delays for subsequent sessions.