SFTP error "Received message too long"

Configure your server to use the internal sftp server adding the following directive to /etc/ssh/sshd_config:

Subsystem sftp internal-sftp

That way, it will not use the user shell to launch the sftp server program.


"Received message too long" means that your SFTP client received bad data from the SFTP server. The typical reason is that the shell startup scripts on the server (.bashrc, .profile, .cshrc, etc.) are producing some output, and your SFTP client is trying to parse that output as an SFTP message. You can check this by running the command:

ssh user@remote 'echo hello'

If this produces any output other than the "hello", then that output would probably prevent SFTP or SCP from working properly.

As in salva's answer, you can avoid this by setting the SSH server to use internal-sftp for SFTP sessions. This avoids launching your shell for SFTP sessions. This won't help with SCP or with other programs like git or rsync which run through ssh.

The other ways to fix this is to go through your shell startup commands, figure out what is producing the output, and prevent that from happening during non-interactive SSH sessions. One tip is to test for a TTY before running commands which produce output:

if [ -t 1 ]; then
    # standard output is a TTY
    ...
fi

Tags:

Linux

Sftp