How to fix Connection closed in SSH

SSHINTERMEDIATEMEDIUMUpdated Aug 5, 2026· 757 views

This error occurs when an SFTP connection is abruptly terminated before the operation completes. It typically indicates a server-side issue, network instability, missing SFTP subsystem configuration, or server resource constraints.

Quick fix

Fixes Connection closed

ssh -v user@host
  1. Verify basic SSH connectivity first
  2. Test SFTP with verbose logging
  3. Verify SFTP subsystem is configured on the server
  4. Verify SFTP server binary exists and is executable
ssh — error
ssh -v user@host
Connection closed

What this error means

The SFTP connection closed error means that the SSH connection was established successfully, but the SFTP session terminated unexpectedly before completing file operations. This is different from a connection timeout—the connection was made but dropped prematurely. The causes range from missing SFTP subsystem configuration (especially on Windows) to network issues, idle timeouts, or server errors. When investigating, check both server logs and client-side connection details to determine whether the server intentionally closed the connection or if it crashed.

Typical symptoms

  • SFTP connection works initially, then closes during file transfer
  • File upload or download fails midway with 'Connection closed'
  • Connection drops immediately after authentication on Windows
  • Works with SSH but fails specifically with SFTP
  • Intermittent failures during large file transfers
  • Connection closes after a period of inactivity

Common causes

  1. SFTP subsystem is not configured or not found on the server (especially on Windows OpenSSH)
  2. SFTP server binary is missing or path is incorrect in sshd_config
  3. SSH daemon crashes or terminates unexpectedly due to errors
  4. Network connectivity issues or packet loss during transfer
  5. Server-side idle timeout closing inactive connections
  6. Firewall or network middlebox resetting idle connections
  7. User shell is incorrectly configured or not available
  8. Server resource exhaustion (CPU, memory, or file descriptor limits)
  9. SSH authentication successful but SFTP service unavailable

How to fix "Connection closed"

1Verify basic SSH connectivity first

Test that regular SSH works before troubleshooting SFTP:

bash
ssh -v user@host

If SSH connection succeeds but SFTP fails, the issue is likely SFTP-specific (missing subsystem). If SSH also fails, troubleshoot SSH connectivity first.

2Test SFTP with verbose logging

Use the -v flag with SFTP to see detailed diagnostic information:

bash
sftp -v user@host

For even more detail:

bash
sftp -vv user@host

Watch for error messages about subsystem requests or authentication failures. Verbose output often shows exactly where the connection closes and why.

3Verify SFTP subsystem is configured on the server

On the remote server, check that the SFTP subsystem is properly configured in sshd_config:

bash
grep -i subsystem /etc/ssh/sshd_config

You should see a line like:

bash
Subsystem sftp /usr/lib/openssh/sftp-server

On Windows OpenSSH, check:

powershell
Get-Content 'C:\ProgramData\ssh\sshd_config' | Select-String -Pattern 'Subsystem'

Should show:

bash
Subsystem sftp C:\\Windows\\System32\\OpenSSH\\sftp-server.exe

If the subsystem line is commented out or missing, uncomment it or add it.

4Verify SFTP server binary exists and is executable

Check that the SFTP server binary actually exists at the path specified in sshd_config:

Linux/Unix:

bash
ls -la /usr/lib/openssh/sftp-server

or

bash
ls -la /usr/libexec/sftp-server

Windows:

powershell
Test-Path 'C:\\Windows\\System32\\OpenSSH\\sftp-server.exe'

The binary must exist and be executable. If it's missing, you may need to reinstall OpenSSH or correct the path in sshd_config.

5Restart the SSH daemon after configuration changes

After modifying sshd_config, reload or restart the SSH service:

Linux/Unix:

bash
sudo systemctl reload ssh
# or
sudo systemctl restart ssh

Windows (PowerShell as Admin):

powershell
Restart-Service -Name sshd -Force

A reload applies configuration without dropping existing connections. A restart is more thorough if reload doesn't work.

6Check server logs for SFTP errors

Examine the SSH daemon logs to see what happens when SFTP connection fails:

Linux/Unix:

bash
sudo tail -f /var/log/auth.log
# or
sudo journalctl -u ssh -n 50
sudo journalctl -u sshd -n 50

Windows (PowerShell as Admin):

powershell
Get-EventLog -LogName System | Where-Object { $_.Source -like '*ssh*' } | Select-Object -Last 20

Look for errors mentioning "subsystem" or "sftp". Messages like "subsystem request for sftp failed" confirm the subsystem is missing or not found.

7Verify user shell configuration

Some SFTP configurations require users to have a valid login shell. Check the user's shell:

bash
grep ^username: /etc/passwd

The last field should be a valid shell (e.g., /bin/bash, /bin/sh). If it's /sbin/nologin or /bin/false, SFTP may fail.

You can also configure SFTP to work even with nologin shells by using chroot or ForceCommand in sshd_config:

bash
Match User sftpuser
  ForceCommand internal-sftp
  ChrootDirectory /home/sftpuser
  PermitTTY no
  AllowAgentForwarding no
  AllowTcpForwarding no
EndMatch
8Test from a different SFTP client

Try connecting with a different SFTP client to isolate whether the issue is client-specific:

Command line:

bash
sftp user@host

Alternative clients:
- FileZilla (GUI)
- WinSCP (Windows GUI)
- Cyberduck (GUI)
- lftp (command line)

bash
lftp -u user sftp://host

If the issue persists across multiple clients, it's a server problem. If only one client fails, check client-specific settings.

9Increase SSH and SFTP timeouts if experiencing intermittent issues

If connections drop after inactivity, adjust timeout settings:

Client-side (~/.ssh/config):

bash
Host *
  ServerAliveInterval 60
  ServerAliveCountMax 5

Or on the command line:

bash
sftp -o ServerAliveInterval=60 user@host

Server-side (/etc/ssh/sshd_config):

bash
ClientAliveInterval 300
ClientAliveCountMax 3

These settings keep the connection alive by sending periodic keepalive packets, preventing idle timeout.

Advanced notes

Windows OpenSSH SFTP Issues: The most common cause on Windows is incorrect sftp-server.exe path in sshd_config. Ensure the full path is specified and includes escaped backslashes: C:\\Windows\\System32\\OpenSSH\\sftp-server.exe. If the path contains spaces, quote it.

Chroot SFTP Jails: If using ChrootDirectory for SFTP-only users, ensure directory ownership and permissions are correct. The root directory and all parent directories must be owned by root with 755 permissions, or OpenSSH will refuse to enter the chroot and close the connection.

Large File Transfers: Connection drops during large transfers often indicate insufficient buffer sizes or network instability. Try breaking transfers into smaller chunks or using a client with resume capability.

SFTP over Jump Host/Bastion: If connecting through a jump host, the connection may close if the bastion doesn't have SFTP subsystem configured. Verify all servers in the chain (jump host and final destination) have SFTP configured.

Cloud VMs (AWS, Azure, GCP): Ensure security groups and network ACLs allow port 22 (SSH) throughout the transfer. Some cloud providers may have network policies that interrupt long-lived connections.

SELinux/AppArmor: Mandatory access control systems can prevent sftpd from running. Check denial logs: sudo ausearch -m avc for SELinux or sudo journalctl -u apparmor for AppArmor.

Frequently asked questions

What does "Connection closed" mean?
The SFTP connection closed error means that the SSH connection was established successfully, but the SFTP session terminated unexpectedly before completing file operations. This is different from a connection timeout—the connection was made but dropped prematurely. The causes range from missing SFTP subsystem configuration (especially on Windows) to network issues, idle timeouts, or server errors.
How do I fix "Connection closed"?
This error occurs when an SFTP connection is abruptly terminated before the operation completes. It typically indicates a server-side issue, network instability, missing SFTP subsystem configuration, or server resource constraints.
What causes "Connection closed"?
SFTP subsystem is not configured or not found on the server (especially on Windows OpenSSH) SFTP server binary is missing or path is incorrect in sshd_config SSH daemon crashes or terminates unexpectedly due to errors
Is the "Connection closed" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading