If you searched your way here, one of these is probably on your screen:
scp: write local "./backup.tar.gz": File too large
scp: open local "./mail/cur/1700000000000:": Invalid argument
scp: Received message too long 1349281121
scp: Ensure the remote shell produces no output for non-interactive sessions.
subsystem request failed on channel 0
scp: Connection closed
Or the progress meter stops at 4112MB on every attempt and never moves again.
I hit all four in 2026, the last one four times in six months. Each message points at a different layer: the filesystem you are writing to, the characters that filesystem accepts in a name, the remote user’s shell startup files, and the server’s SFTP configuration. Once you know which layer a message belongs to, one check usually confirms it and the fix follows. This is a reference for anyone who copies files with scp.
Last verified: December 2026 against OpenSSH 10.6p2 (released November 5, 2026; source tree as of November 30, 2026), exfatprogs 1.4.5, the rsync manual, and the Linux kernel source as of December 1, 2026. Error lines come from my own terminal with paths and names replaced. The decoding, split and checksum commands were run on an Ubuntu 24.04 test machine (bash 5.2.21, GNU coreutils 9.4). The scp and sshd commands were not rerun for this article. Their expected output comes from the real incidents or from the OpenSSH source.
How It Works
Since OpenSSH 9.0 (April 2022), scp uses the SFTP protocol by default. It opens an SSH connection and asks the server’s sshd for the subsystem named sftp (a subsystem is a named service that sshd starts on request instead of a shell command). Then it exchanges SFTP packets with whatever program sshd started. Every SFTP packet starts with a 4-byte big-endian length.
The -O flag switches scp back to the legacy SCP protocol. In that mode scp runs a copy of scp on the server through the remote user’s shell and speaks a simpler line-based protocol. The OpenSSH developers described that protocol in the 8.0 release notes as “outdated, inflexible and not readily fixed”. Treat -O as a workaround, not a default.
On the server, the Subsystem sftp line in /etc/ssh/sshd_config decides what runs:
- A path, such as
/usr/lib/openssh/sftp-server, is started through the user’s shell (the one set in/etc/passwd) with-c. The shell’s startup files run first. internal-sftpruns an SFTP server inside sshd itself. No shell is started.- No
Subsystem sftpline means no SFTP at all. OpenSSH’s built-in default is no subsystems. Distribution packages add the line to the config file they ship.
On your machine, scp writes files with ordinary system calls. When the kernel refuses one, scp prints the operating system’s text for the error code: “File too large” is EFBIG and “Invalid argument” is EINVAL.
Where each failure happens. The two filesystem errors are on your side, the other two are on the server.
| Message | Layer | First check |
|---|---|---|
File too large, or a stall at about 4112 MB |
Destination filesystem (FAT32 size limit) | df -hT on the destination shows vfat |
Invalid argument on names containing : |
Destination filesystem (forbidden characters) | df -hT shows vfat or exfat |
Received message too long <N> |
Remote shell startup files | ssh <USER>@<HOST> true \| wc -c is not 0 |
subsystem request failed on channel 0 |
Server’s sshd config | sudo sshd -T \| grep -i '^subsystem' prints nothing |
Prerequisites
- An OpenSSH client.
ssh -Vshows the version; on 9.0 or later, plain scp uses SFTP. - SSH access to the server with key-based login (the sftp test in failure 4 does not prompt for a password).
- sudo on the server for the server-side fixes.
- For the FAT32 fixes: the
exfatprogspackage formkfs.exfat, and rsync installed on both machines.
scp: write local “file”: File too large (or a Copy That Stops at 4112 MB)
What Happened
The first time, I was copying a tarball from a backup server onto a USB stick:
backup.tar.gz 41% 4112MB 103.3MB/s 00:55 ETA
scp: write local "./backup.tar.gz": File too large
The second time, nine months later, I was copying a zip of well over 4 GB onto a different USB drive with scp -r (the -r was unnecessary for a single file). The progress line stopped at 28% 4112MB on every attempt. Same offset each time means it is not the network. Something fails at a fixed byte position, and 4112 MB is just past 4 GiB.
Cause
Both drives were FAT32. FAT32 stores a file’s size in a 32-bit field, so the largest file it can hold is 4,294,967,295 bytes: 4 GiB minus 1 byte. The Linux FAT driver sets that as the filesystem’s maximum file size (s_maxbytes = 0xffffffff), so the write that would cross it fails with EFBIG. scp prints that as “File too large”.
Why 4112 and not 4096: scp’s progress meter counts in units of 1024, and it counts data as it arrives, not as it is written. Against an OpenSSH server, scp keeps up to 64 read requests of about 255 KiB each in flight, roughly 16 MiB, and data that arrives after the failed write is still counted. That is my reading of the client source, and it matches both incidents.
How to Confirm
On your machine, check the destination’s filesystem type:
df -hT /media/$USER/<DRIVE_LABEL>
lsblk -f
vfat in the Type column of df, or vfat with FAT32 under FSTYPE and FSVER in lsblk -f, confirms it. My second drive showed exactly that.
Fix
You have two options. Reformatting is cleaner. Splitting keeps the drive as it is.
Option A: reformat the drive. This erases everything on it. Use exFAT if the drive also has to work on Windows or macOS, or ext4 if it only ever plugs into Linux. exFAT’s file size limit is 2^64 minus 1 bytes, so it is no longer the bottleneck. Identify the partition first and read the output twice, because formatting the wrong device is not recoverable:
lsblk -f
sudo umount /dev/<sdX1>
sudo mkfs.exfat -L <LABEL> /dev/<sdX1>
mkfs.exfat comes from the exfatprogs package. The documented volume label flag is -L (-n is still accepted as an alias for older scripts). Since exfatprogs 1.4.0 (May 2026), mkfs.exfat run from a terminal refuses to overwrite a device that already holds a filesystem and prints Device has existing signatures. Refusing to overwrite; use -F to force. Add -F only after you have confirmed the device name. For a Linux-only drive, sudo mkfs.ext4 -L <LABEL> /dev/<sdX1> instead. A fresh ext4 filesystem’s top directory belongs to root, so after it remounts run sudo chown "$USER": /media/$USER/<LABEL>.
Unplug and replug the drive, confirm lsblk -f now shows exfat or ext4, then copy with rsync instead of scp:
rsync -avP -e "ssh -o ServerAliveInterval=30" \
<USER>@<HOST>:/srv/backups/archive.zip /media/$USER/<LABEL>/
This is what fixed my November copy, and the checksums on both ends matched afterwards. -P is shorthand for --partial --progress. --partial keeps a partly transferred file instead of deleting it, so if the copy dies you run the same command again and rsync reuses what already arrived. scp starts from zero. rsync also checks each transferred file against a whole-file checksum as it goes. ServerAliveInterval=30 makes ssh send a keepalive after 30 seconds of silence, which stops idle-connection timeouts on the path from killing a long copy. rsync must be installed on both machines.
Option B: keep FAT32 and split the file while it streams. Each piece must be under 4 GiB. split writes the pieces into the current directory, so change to the drive first:
cd /media/$USER/<DRIVE_LABEL>
ssh <USER>@<HOST> 'cat /srv/backups/archive.zip' | split -b 3900M -d - archive.zip.part
3900M is 3,900 MiB (4,089,446,400 bytes), safely under the limit. -d gives numeric suffixes, so you get archive.zip.part00, archive.zip.part01 and so on. The - tells split to read standard input. Run the shell check from failure 3 first (ssh <USER>@<HOST> true | wc -c must print 0), because anything a startup file prints lands at the front of this stream and corrupts the first piece.
To rebuild the file later, write the output to a filesystem that can hold it, such as your home directory:
cat /media/$USER/<DRIVE_LABEL>/archive.zip.part* > ~/archive.zip
Verify the Copy
Compare checksums on both ends. They must match exactly.
ssh <USER>@<HOST> 'sha256sum /srv/backups/archive.zip'
sha256sum /media/$USER/<LABEL>/archive.zip
For the split version, hash the pieces in order without reassembling them:
cat /media/$USER/<DRIVE_LABEL>/archive.zip.part* | sha256sum
The hash is identical to the original’s because cat feeds the same bytes in the same order. You can confirm it the same way on a small test file.
scp: open local “…:”: Invalid argument
What Happened
Earlier in that same February restore, before I tried a tarball, I had pointed scp -r at a directory of old mail stored in Maildir format and copied it straight onto the FAT32 stick. The message files failed one after another:
scp: open local "./mail/cur/1700000000000:": Invalid argument
scp: Download of file /srv/backups/mail/cur/1700000000000: to ./mail/cur/1700000000000: failed
Then the tarball ran into failure 1. After the stick was reformatted to exFAT, extracting the tarball onto it failed the same way:
tar: mail/cur/1700000000000\:S: Cannot open: Invalid argument
Reformatting to exFAT fixed the size limit and changed nothing about the names.
Cause
Maildir puts flags in the filename after a colon, in the form unique:2,FLAGS (for example S for a message that has been read). Neither FAT32 nor exFAT allows a colon in a name. In the Linux kernel, the vfat driver rejects : along with " * / < > ? \ | and control characters, and returns EINVAL. The exFAT driver rejects the same set with the same error. “Invalid argument” is the kernel refusing the name. scp read it correctly, and rsync or cp would hit the same refusal.
How to Confirm
df -hT <DESTINATION_DIR>
ssh <USER>@<HOST> "find /srv/backups/mail -name '*:*' | head"
A destination of vfat or exfat plus source names containing : is the whole story. The same applies to any other forbidden character in that list.
Fix
Write the files to a filesystem that accepts colons. A Linux-native filesystem such as ext4 accepts any byte in a name except / and the NUL byte. My fix was extracting the tarball into my home directory, which is on ext4.
If the files have to travel on a FAT-family drive, keep them inside an archive and only extract them onto a Linux filesystem. Put the archive on exFAT (or split it as in failure 1), because one big tarball runs straight into the 4 GiB limit on FAT32. Run the shell check from failure 3 first, because stray startup output would land at the front of the archive:
ssh <USER>@<HOST> 'tar -C /srv/backups -czf - mail' > /media/$USER/<LABEL>/mail.tar.gz
You could rename the files instead (GNU tar’s --transform 's/:/_/g' does it on extraction), but for Maildir that destroys the flags: a mail server reads _2,S as part of the unique name, not as “seen”.
scp: Received message too long 1349281121
What Happened
In March and again in June, copying a single file to or from the same web server:
scp: Received message too long 1349281121
scp: Ensure the remote shell produces no output for non-interactive sessions.
The number was identical both times. That is a clue in itself: a random network fault would not produce the same number twice.
Cause
scp in SFTP mode reads the first 4 bytes from the server as the length of the first packet. If anything prints text before the SFTP server starts (a shell startup file, typically), scp reads the first four characters of that text as the length. The client rejects any length over 256 KiB (262,144 bytes). Four printable ASCII characters are always at least 0x20202020, which is 538,976,288, so any stray text trips the check. The second line of the error is the client telling you exactly that.
Bash makes this easy to trigger. When bash detects that sshd started it to run a command, it reads ~/.bashrc even though the shell is not interactive. That behavior is documented in the bash manual and depends on how bash was built. Ubuntu’s build does it, and a quick test with ssh <HOST> 'echo $-' plus a marker line in ~/.bashrc shows it. zsh reads ~/.zshenv for every shell, interactive or not.
Decode the Number
The number is just the four stray bytes read as a big-endian integer. Turn it back into text:
python3 -c 'import struct, sys; print(struct.pack(">I", int(sys.argv[1])))' 1349281121
b'Plea'
Without Python:
n=1349281121; printf "$(printf '\\x%02x\\x%02x\\x%02x\\x%02x' $((n>>24&255)) $((n>>16&255)) $((n>>8&255)) $((n&255)))\n"
Plea
So the server’s output started with the four characters Plea, the beginning of some sentence. I did not record which file printed it, so I cannot tell you what the rest of the line said. What the decode gives you is a string to search for on the server:
grep -n 'Plea' ~/.bashrc ~/.bash_profile ~/.profile ~/.zshenv /etc/bash.bashrc /etc/profile /etc/profile.d/* ~/.ssh/authorized_keys 2>/dev/null
authorized_keys is on that list because a command="..." option on a key runs that command every time the key is used. If a forced command prints text, you get this same error, and no shell-file guard will fix it.
How to Confirm
Run a command over SSH that should produce no output, and count the bytes:
ssh <USER>@<HOST> true | wc -c
Anything other than 0 is your culprit. Pipe through od -c | head instead of wc -c to see it. rsync’s manual describes the same test, because rsync fails the same way (its version of the message is “protocol version mismatch – is your shell clean?”).
Workaround
What got my file onto the server in June was a plain pipe through ssh:
cat ./file.crt | ssh <USER>@<HOST> 'cat > /tmp/file.crt'
This works for uploads because the stray text goes to your terminal, not into the file. Do not reverse it for downloads. ssh <USER>@<HOST> 'cat file' > local puts the stray text at the front of your local copy. Try it on a test file and you will see it. It also does nothing when the text comes from a command= forced command, because that command runs instead of yours.
scp -O does not help here. The legacy protocol also starts through the remote shell, so it fails too. It does print the stray line as its error message, which at least shows you what the text is.
Fix
Stop the startup file from printing in non-interactive shells. Find the offending line on the server and wrap it:
case $- in
*i*) echo "Welcome to the build server" ;;
esac
$- holds the current shell’s option letters and contains i only when the shell is interactive. An equivalent guard that tests the output directly:
if [ -t 1 ]; then
echo "Welcome to the build server"
fi
[ -t 1 ] is true only when standard output is a terminal. A plain ssh host command does not allocate one. Ubuntu’s default ~/.bashrc (copied from /etc/skel) already starts with an early return for non-interactive shells, so the usual offender is a line someone added above that return, or a startup file that has no such check.
On a server you control there is a second fix: Subsystem sftp internal-sftp (see failure 4). sshd then runs SFTP without starting a shell, so startup files never get a chance to print. That fixes scp and sftp only. rsync and ssh host command still see the output, so clean up the startup file anyway.
Run the confirmation again. ssh <USER>@<HOST> true | wc -c must print 0.
subsystem request failed on channel 0
What Happened
This is the one I hit four times between March and August:
subsystem request failed on channel 0
scp: Connection closed
The first line comes from ssh, which scp runs underneath it to carry the connection. The second comes from scp when the connection ends before the first SFTP reply.
Cause
sshd refused the request for the sftp subsystem. In the OpenSSH source that happens when sshd has no Subsystem sftp entry, or when it cannot start the session for it. Because OpenSSH’s default is no subsystems, a config that lost its distribution’s Subsystem line has no SFTP. So does a hand-written minimal config, or an SSH server that never implemented SFTP. scp clients older than 9.0 did not use SFTP by default, which is why an upgrade on your side can make this appear against a server that has not changed.
A related variant: if the Subsystem line exists but points at a path that does not exist, sshd accepts the request and the shell fails to run the binary. Then you see scp: Connection closed, possibly with a “not found” message from the remote shell, but no “subsystem request failed” line.
How to Confirm
On your machine, check your client version and whether plain sftp fails the same way:
ssh -V
echo bye | sftp -b - <USER>@<HOST>
-b - makes sftp read its commands from standard input, so this connects, says bye and exits. Batch mode also turns off password prompts, so it needs key-based login. The same “subsystem request failed” line here means the problem is SFTP on the server, not scp.
If you have access to the server, ask sshd for its effective configuration:
sudo sshd -T | grep -i '^subsystem'
No output means no SFTP subsystem. sshd’s log for the failed attempt says subsystem request for sftp by user <USER> failed, subsystem not found.
Workaround
Force the legacy protocol for this copy:
scp -O <USER>@<HOST>:/path/to/file .
It needs scp installed on the server, and it carries the legacy protocol’s caveats: the remote shell expands the path, so quote filenames with spaces or special characters carefully.
Fix
On the server, add or correct the Subsystem line. Open the config (in vim, press i to insert, then Esc and :wq to save and quit):
sudo vim /etc/ssh/sshd_config
I would use the in-process server:
Subsystem sftp internal-sftp
It needs no separate binary, it does not start the user’s shell (so it also sidesteps failure 3), and it works with ChrootDirectory. One side effect: a umask set in a shell startup file no longer applies to uploaded files. If you relied on one, add it to the line, as in Subsystem sftp internal-sftp -u 022.
If you prefer the external binary, use its path on your system and check that it exists first. Other distributions may differ, so trust ls over the table:
| Distribution | sftp-server path | Package |
|---|---|---|
| Debian, Ubuntu | /usr/lib/openssh/sftp-server |
openssh-sftp-server |
| Fedora | /usr/libexec/openssh/sftp-server |
openssh-server |
OpenSSH’s own sample sshd_config |
/usr/libexec/sftp-server |
n/a |
ls -l /usr/lib/openssh/sftp-server
Subsystem sftp /usr/lib/openssh/sftp-server
Since OpenSSH 9.5, sshd uses the first Subsystem sftp line it reads and silently ignores later ones. Older versions refuse to start on a duplicate, which sshd -t reports. Replace the existing line instead of adding a second, and check /etc/ssh/sshd_config.d/ for a drop-in that defines one. sshd -T shows which one won.
Validate the config, then restart. Keep your current SSH session open and test from a second terminal, so a mistake does not lock you out:
sudo sshd -t && sudo systemctl restart ssh.service
On Fedora the unit is sshd.service. sshd -t prints nothing when the config is valid.
Verify
These checks cover all four failures. Run them before a large or important copy, not only after one fails.
- Your client version.
ssh -Vprints something likeOpenSSH_9.6p1 .... On 9.0 or later, plainscpuses SFTP. - The remote shell is silent.
ssh <USER>@<HOST> true | wc -cprints0. - SFTP works.
echo bye | sftp -b - <USER>@<HOST>exits without a “subsystem request failed” line, andecho $?afterwards prints0. - The destination can hold the files.
df -hT <DESTINATION>shows a type other thanvfatfor anything over 4 GiB, and other thanvfatorexfatfor names containing:or the other forbidden characters. - The copy is intact.
sha256sumon both ends prints the same hash.
Sources and further reading
- OpenSSH 9.0 release notes: scp switched to SFTP by default,
-Oselects the legacy protocol, release date 2022-04-08. - OpenSSH 8.0 release notes: the scp protocol described as outdated, and CVE-2019-6111.
- OpenSSH release notes index: 10.6p2 as the current release (2026-11-05).
- scp(1): SFTP by default since 9.0,
-O, and the legacy protocol’s reliance on the remote shell. - sshd_config(5):
Subsystem,internal-sftp, and “By default no subsystems are defined.” - sftp-server(8): the external SFTP server and its
-u umaskflag. - sftp(1):
-b -reads batch commands from standard input. - sshd(8):
-t,-T, and thecommand=key option. - OpenSSH portable source: sftp-client.c: the “Received message too long” check, the 256 KiB limit, “write local” and “open local” errors, and the progress counter.
- OpenSSH portable source: session.c: external subsystems run through the user’s shell with
-c,internal-sftpruns in-process, and the “subsystem not found” log line. - Linux kernel: fs/fat/inode.c and fs/fat/namei_vfat.c: FAT’s 0xffffffff maximum file size and the characters vfat rejects with
EINVAL. - Linux kernel: fs/exfat/nls.c and fs/exfat/namei.c: the characters exFAT rejects.
- Microsoft: File system functionality comparison: FAT32 and exFAT maximum file sizes.
- exfatprogs:
mkfs.exfat -L, and the 1.4.0 change that requires-Fto overwrite an existing filesystem. - rsync(1):
-P,--partial, whole-file verification, and the “is your shell clean?” diagnostic. - Bash manual: Bash Startup Files and Is this Shell Interactive?:
.bashrcunder sshd, and the$-test. - zsh: Startup/Shutdown Files:
.zshenvis read by every zsh. - Maildir specification: the
:2,info suffix and flag letters. - Ubuntu Server: OpenSSH server:
sshd -tandsystemctl restart ssh.service.