Skip to content

Resolving 'subsystem request failed on channel 0' in SCP

Problem Description

When using the scp command to securely copy files between systems, you might encounter this error:

subsystem request failed on channel 0
scp: Connection closed

This typically occurs when running commands like:

bash
scp -p -P 29418 user@host:source_path destination_path

The error indicates a protocol failure between your SSH client and the remote server during file transfer initiation. Common environments where this occurs include:

  • Older SSH server implementations
  • Windows-based OpenSSH servers
  • Custom-configured SSH servers using non-standard setups

Solution: Use Legacy SCP Protocol with -O Flag

Add the -O option to your scp command to force use of the legacy SCP protocol:

bash
scp -p -O -P 29418 user@host:source_path destination_path

Why This Works

  • The -O flag bypasses the newer SFTP protocol and reverts to the original SCP transfer mechanism
  • Some servers don't fully implement the SFTP subsystem correctly
  • Older servers (particularly on Windows) might have configuration quirks preventing proper SFTP negotiation
  • The legacy protocol maintains security since it still operates over SSH encryption

Protocol Differences

FeatureSCP Protocol (-O)SFTP Protocol (Default)
Transfer Methodrcp-style protocolSSH File Transfer Protocol
Server CompatibilityBetter for older/Windows serversModern standard
Wildcard HandlingOriginal expansion rulesPOSIX-compliant
Path ExpansionHandles ~ prefixesStandard implementation
Security BasisSSH encrypted channelSSH encrypted channel

Implementation Example

bash
# Original failing command:
scp -p -P 29418 michealvern.genzola@192.168.0.122:hooks/commit-msg "jyei-erp/.git/hooks/"

# Fixed version with -O:
scp -p -O -P 29418 michealvern.genzola@192.168.0.122:hooks/commit-msg "jyei-erp/.git/hooks/"

Additional Considerations

  1. Windows OpenSSH Servers: This error frequently occurs with PowerShell's Win32-OpenSSH implementation. A GitHub issue confirms the -O workaround is effective.

  2. Alternative Solutions:

    bash
    # Try using rsync instead (if available)
    rsync -e 'ssh -p 29418' -av user@host:source_path destination_path
    
    # Use sftp with batch mode (requires different syntax)
    echo "get remote_path local_path" | sftp -P 29418 user@host

When Not to Use -O

The legacy SCP protocol has limitations:

  • Doesn't support newer SSH features like transfer resumption
  • Limited error handling capabilities
  • Wildcard expansion differences Only use -O when necessary for compatibility
  1. Server Configuration Fixes:
    If you control the server, consider these permanent solutions:
    • Update SSH server software
    • Verify subsystem configuration in /etc/ssh/sshd_config:
      Subsystem sftp /usr/lib/openssh/sftp-server
    • Restart SSH service after changes

Troubleshooting Flowchart

This solution addresses a common interoperability issue between modern SCP clients and servers with incomplete SFTP implementations. The -O flag provides a reliable client-side workaround while maintaining secure data transfer through SSH encryption.