scp "subsystem request failed on channel 0" and "scp: Connection closed"
Since OpenSSH 9.0, scp uses SFTP. A host with no sftp Subsystem line refuses it. Add the line on the server, or copy with scp -O, the legacy protocol.
subsystem request failed on channel 0
scp: Connection closed
SSH login to the host works, but scp stops with these two lines. sftp to the same host stops the same way, with Connection closed.
Why it happens
Since OpenSSH 9.0, scp copies files with the SFTP protocol by default. It opens an SSH session and asks the server for the sftp subsystem, the same request the sftp command makes. Before 9.0, scp ran an scp command in the remote shell instead.
On an OpenSSH server, a subsystem exists only if sshd_config names it on a Subsystem line. The manual says that by default no subsystems are defined; the line usually comes from the configuration file that ships with the server package. If the line is missing, the server refuses the request. The client then prints subsystem request failed on channel 0 and gives up, and scp adds Connection closed.
The same happens with any SSH server that offers a shell but no SFTP server.
Check the line above "Connection closed"
scp: Connection closed on its own only says that the SSH connection ended. The line before it tells you why:
- subsystem request failed on channel 0: the server has no
sftpsubsystem. Read on. - Permission denied (publickey) or another login error: the login failed, and SFTP never started. See SSH error messages, what each one means.
- An error from the shell, such as
No such file or directorywith a path tosftp-server: theSubsystemline exists, but the program it names is not installed at that path. - Received message too long: a shell startup file printed text. See SFTP "Received message too long".
Fix it on the server
See what the server uses. sshd -T prints the configuration as the server reads it. No output from this command means no subsystem is defined:
sudo sshd -T | grep -i subsystem
Add one line to /etc/ssh/sshd_config. Either name the external SFTP server program, at the path where your system installs it:
Subsystem sftp /usr/lib/openssh/sftp-server
or use the SFTP server built into sshd, which needs no separate program:
Subsystem sftp internal-sftp
The program path differs between systems. Debian and Ubuntu install it as /usr/lib/openssh/sftp-server, in its own package, openssh-sftp-server. Fedora and other Red Hat family systems use /usr/libexec/openssh/sftp-server.
Check and reload. Run sudo sshd -t to test the file, then reload or restart the SSH service. The new setting applies to new connections.
Only the first Subsystem sftp line counts. OpenSSH ignores a later line with the same name, so editing a duplicate further down changes nothing.
Work around it from the client: scp -O
If you cannot change the server, use the legacy protocol:
scp -O report.txt [email protected]:/tmp/
The scp manual says -O may be needed for servers that do not implement SFTP. The legacy protocol runs scp through your login shell on the host, so the host must have an scp program in its path, and the shell must not print anything at login. It also expands wildcards in remote names through that shell, so quote special characters in remote file names.
sftp has no such switch. Without an SFTP subsystem on the host, sftp and SFTP-based file browsers cannot connect; use scp -O or ask the administrator to add the line.
Other subsystems
The message names the request that failed, not only SFTP. For example, PowerShell remoting over SSH asks for a powershell subsystem, and Microsoft's setup adds a Subsystem powershell line for it. Without that line you get the same subsystem request failed message.
Related
- SFTP
- SFTP "Received message too long"
- Do scp and sftp use ~/.ssh/config? Host aliases, -F and -P
- SSH error messages, what each one means
Sources
- OpenSSH 9.0 release notes: scp uses the SFTP protocol by default
- scp(1): option -O and Caveats
- sshd_config(5): Subsystem
- sshd(8): option -T
- OpenSSH clientloop.c: "request failed on channel"
- OpenSSH servconf.c: a repeated Subsystem name is ignored
- Debian package openssh-sftp-server: file list
- Fedora openssh.spec: libexecdir /usr/libexec/openssh
- Microsoft Learn: PowerShell remoting over SSH