Need Assistance?

In only two hours, with an average response time of 15 minutes, our expert will have your problem sorted out.

Server Trouble?

For a single, all-inclusive fee, we guarantee the continuous reliability, safety, and blazing speed of your servers.

Solving the SFTP “ECONNREFUSED – Connection Refused by Server” Error

When you attempt to connect to your server using SFTP and encounter the ECONNREFUSED – Connection refused by server error, it can be frustrating. This error typically indicates that the server is actively refusing the connection. There are several potential causes for this issue, but in many cases, it’s related to how SSH is configured on the server. In this blog, we’ll walk through the steps to resolve this error.

Understanding the Error “ECONNREFUSED – Connection Refused by Server”

The “ECONNREFUSED – Connection Refused by Server” error can occur for various reasons, often due to incorrect or restrictive settings in the SSH configuration file (sshd_config) when using SFTP. By default, some SSH configurations may prevent SFTP connections for certain users or limit the allowed authentication methods, resulting in this error. To resolve the “ECONNREFUSED Connection Refused by Server” issue, you need to adjust the SSH configuration to ensure proper SFTP functionality and grant the necessary permissions for users.

1. Allow Password Authentication for SFTP Users:

A common cause of the ECONNREFUSED error is that password authentication for SFTP users is disabled. Often, password authentication is turned off on the server for security purposes, leaving only key-based authentication enabled, which can result in the SFTP connection being refused. To fix this ECONNREFUSED error issue, you’ll need to edit the SSH configuration file located at /etc/ssh/sshd_config.

sudo nano /etc/ssh/sshd_config

Then, add the following line at the end of the file (adjusting sftpuser to match your actual SFTP user):

Match User sftpuser
    PasswordAuthentication yes

This allows password authentication for the specified user, sftpuser, which can be critical if other methods, like public key authentication, are not properly configured or disabled.

2. Switch the SFTP Subsystem:

Another common issue that can lead to the connection being refused is the default subsystem configuration for SFTP. By default, SSH may be configured to use the /usr/lib/openssh/sftp-server as the SFTP subsystem. However, using internal-sftp can sometimes resolve connection issues.

In the sshd_config file, look for the line that specifies the SFTP subsystem and comment it out (hash it). Then, add the following line:

#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp

The internal-sftp subsystem is often more reliable for restricted SFTP sessions.

3. Restart SSH Service:

After making these changes, you need to restart the SSH service to apply the new configurations. You can restart SSH by running the following command:

sudo systemctl restart sshd

In systems using init.d, you can restart SSH by running the following command:

/etc/init.d/ssh restart

Conclusion

The ECONNREFUSED error is a common issue when using SFTP and is often related to SSH server configuration settings. By allowing password authentication for specific users and switching the SFTP subsystem to internal-sftp, you can resolve the issue ECONNREFUSED error and ensure smooth SFTP connections. Always remember to restart the SSH service after making configuration changes to apply them.

If you are facing the Error “ECONNREFUSED – Connection Refused by Server” while using SFTP and need expert assistance, Skynats is here to help. With our Hourly Server Support, we can quickly diagnose and resolve issues related to SFTP connectivity, including errors like ECONNREFUSED Connection Refused by Server.

Liked!! Share the post.

Get Support right now!

Start server management with our 24x7 monitoring and active support team

Let us know your requirement.

Can't get what you are looking for?

Get Support Right Away!

Thank You

We have received your query and will get back to you soon.