The error message “subsystem request failed on channel 0 scp: Connection closed” indicates a problem during the file transfer process using SCP, often related to the underlying SSH/SFTP subsystem on the server.
Here’s a breakdown of potential causes and solutions:
1. OpenSSH 9.0 and SFTP Protocol:
-
Starting with OpenSSH 9.0, the
scpcommand defaults to using the SFTP protocol for file transfers. If the server does not fully support SFTP or has an older, incompatible SFTP implementation, this can lead to the error. -
Force
scpto use the legacy SCP protocol by adding the-Ooption to yourscpcommand.
2. Server-Side Configuration Issues:
-
The SSH server configuration on the remote machine might be incorrectly set up, particularly regarding the SFTP subsystem.
-
- Verify
sshd_config: Check the/etc/ssh/sshd_configfile on the server. Ensure theSubsystem sftpline is present and correctly configured, typically pointing to thesftp-serverbinary (e.g.,/usr/libexec/sftp-serveror/usr/lib/openssh/sftp-server). - Check
sftp-serverbinary: Confirm that thesftp-serverbinary exists at the path specified insshd_configand has the correct permissions. - Restart SSH service: After making any changes to
sshd_config, restart the SSH service on the server (e.g.,sudo systemctl restart sshd).
- Verify
3. Firewall or Network Issues:
-
A firewall on either the client or server side might be blocking the connection or specific ports required for the SFTP/SCP transfer.
-
Temporarily disable firewalls (if safe to do so for testing) or ensure that the necessary ports (typically port 22 for SSH/SFTP) are open.
4. User Permissions or Resource Limits:
-
The user attempting the SCP transfer might have insufficient permissions on the destination path, or the server might be hitting resource limits (e.g., number of processes).
-
- Check permissions: Verify that the user has write permissions to the target directory on the server.
- Increase resource limits: If resource limits are suspected, consult server documentation on adjusting limits for processes or other resources.
5. Debugging Information:
- Solution: Run your
scpcommand with the verbose flag (-vvv) to get more detailed output, which can help pinpoint the exact point of failure.
Review the output for clues about the connection closure or subsystem request failure.
