Software⏱️ 4 min read📅 2026-06-11

How to Fix: Why do I get a “Connection to [host] closed by remote host” error over SFTP connection?

SFTP connection error due to remote host closing the connection.

Quick Answer: Check SFTP server configuration and permissions, ensure proper group access and chroot jail setup.

The 'Connection to [host] closed by remote host' error occurs when an SFTP connection is terminated abruptly by the remote host, preventing you from accessing files or directories on the server. This issue affects users who are trying to establish a secure file transfer protocol (SFTP) connection with a remote host.

This error can be frustrating because it prevents you from completing your file transfer tasks, and it may not always provide clear indications about what went wrong. However, by following these steps, you should be able to resolve the issue and successfully connect to the remote host.

💡 Why You Are Getting This Error

  • The primary reason for this error is that the SFTP server has timed out or terminated the connection due to inactivity or other issues. This can happen when the client (your local machine) fails to send data within a certain time frame, causing the server to assume the connection is idle and close it.
  • Another possible cause could be related to the permissions of the user's home directory or the .ssh/authorized_keys file on the remote host. If the user's home directory lacks the necessary permissions or if the authorized_keys file has incorrect rights, it may prevent the SFTP server from authenticating the user correctly.

🛠️ Step-by-Step Verified Fixes

Check and adjust timeout settings

  1. Step 1: Open a terminal on your local machine and run the following command to increase the connection timeout: sftp -O BatchMode -T 300 user@host.com. This sets the timeout to 5 minutes, allowing you to stay connected for longer periods.
  2. Step 2: Alternatively, you can try increasing the timeout value in the /etc/ssh/sshd_config file by uncommenting the 'Timeout' line and setting it to a higher value (e.g., 300). After making these changes, restart the SSH service using the command sudo systemctl restart sshd.
  3. Step 3: If this method doesn't work for you, try resetting the connection timeout to its default value using the following command: sftp -O BatchMode -T 60 user@host.com.

Verify permissions and authorize keys

  1. Step 1: On the remote host, check the permissions of the user's home directory (e.g., /home/user) using the ls -ld command. Ensure that the user has read and write access to this directory.
  2. Step 2: Next, verify the .ssh/authorized_keys file for the specified user (in your case, 'user'). You can do this by running the command ssh user@host.com 'ls -l ~/.ssh/authorized_keys'. If the file exists but lacks proper permissions, you may need to adjust its ownership or group settings. For example, you can use the following commands: chown user:user ~/.ssh/authorized_keys and chmod 600 ~/.ssh/authorized_keys.

✨ Wrapping Up

To resolve the 'Connection to [host] closed by remote host' error when using SFTP, it is essential to check the connection timeout settings on your local machine. Additionally, verify that the user's home directory has the correct permissions and that the .ssh/authorized_keys file is properly set up. By following these steps, you should be able to establish a secure SFTP connection with the remote host and access files or directories as needed.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions