What's Actually Happening
You successfully authenticate to the SSH server, but the connection closes immediately. The password or key was accepted, but something went wrong when trying to start your session.
The Error You'll See
$ ssh user@server.example.com
user@server.example.com's password:
Last login: Fri Apr 3 10:30:00 2026 from 192.168.1.50
Connection to server.example.com closed.You see the "Last login" message (authentication succeeded) but are immediately disconnected.
Why This Happens
- 1.Shell not found or not executable - Your login shell doesn't exist
- 2.Resource limits exceeded - Process limit, memory limit, or file descriptor limit
- 3.PAM session setup failed - PAM module error
- 4.Chroot/jail misconfigured - Forced command or chroot fails
- 5.Home directory inaccessible - Permissions or mount issues
- 6..bashrc or .profile error - Shell startup script crashes
Step 1: Check Your Login Shell
# From another account or console
grep username /etc/passwdCheck if the shell exists and is executable:
ls -la /bin/bash
ls -la /usr/bin/zsh
# Whatever shell is listedIf the shell is wrong, fix it:
sudo usermod -s /bin/bash usernameStep 2: Check Home Directory
ls -la /home/usernameCheck: - Directory exists - User owns it - User has execute permission on it
sudo chown username:username /home/username
sudo chmod 755 /home/usernameStep 3: Check Resource Limits
```bash # Check user's process limit ulimit -u
# Check max processes system-wide cat /proc/sys/kernel/pid_max
# Check /etc/security/limits.conf grep username /etc/security/limits.conf ```
If user hit their process limit, they can't spawn a shell.
Step 4: Check Shell Init Scripts
The issue might be in your shell configuration:
# Check for syntax errors in bashrc
bash -n /home/username/.bashrc
bash -n /home/username/.bash_profile
bash -n /home/username/.profileCommon issues: - Exit command in the wrong place - Syntax error causing immediate exit - Command that hangs and times out
Step 5: Try a Different Shell
```bash # Connect with a specific shell ssh user@server.example.com /bin/sh
# Or force a command ssh user@server.example.com "ls -la" ```
If this works, the problem is in your normal shell or its config.
Step 6: Check PAM Configuration
```bash # Check PAM logs sudo journalctl -t sshd --since "10 minutes ago" | grep -i pam
# Check PAM config for SSH cat /etc/pam.d/sshd ```
Look for modules that might fail: - pam_limits.so - pam_nologin.so - pam_time.so
Step 7: Check for ForceCommand or Chroot
In /etc/ssh/sshd_config:
grep -E "ForceCommand|ChrootDirectory|AllowTcpForwarding" /etc/ssh/sshd_configIf ForceCommand points to a non-existent command or ChrootDirectory is misconfigured, the session will fail.
Step 8: Check for MOTD or Banner Issues
Sometimes the MOTD (Message of the Day) script fails:
ls -la /etc/update-motd.d/Check scripts for errors or permissions issues.
Verify the Fix
```bash ssh user@server.example.com
# You should get a working shell prompt user@server:~$ ```
No immediate disconnect means the issue is resolved.