SFTP on linux server gives error "Received message too long" [closed]
Asked Answered
D

3

17

I recently tried to using sftp to access my linux box where I implement a simple shell of my own. And I set the users except root to use mine shell in default(by editing /etc/passwd file). Then problem arise, once I tried to access through sftp, I will receive a message saying:

Received message too long

I searched for the solutions and one solution is to change the default shell for this user back to normal bash shell. I tried so and it worked, the problem is that is there a way that I can still using my own shell and also allow sftp to go through? Please answer me with more details like which file I should go editing, etc

Doloroso answered 23/11, 2011 at 23:15 Comment(0)
S
32

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.

Strychnine answered 24/11, 2011 at 9:47 Comment(5)
Worked great, thanks. I had to also add a sudo service sshd restart and I threw in a restart of my sftp daemon (sudo service vsftpd restart) for good measure.Norvun
Thank you; just what I was looking for!Lacunar
A good question and an excellent answer. I did need to comment out the original Subsystem line as it errorred: kex_exchange_identification: read: Connection reset by peer. This error also caused ssh to fail. Commenting out the original 'Subsystem sftp /usr/libexec/sftp-server' did the trick.Abutment
btw, this question was closed. However, the question meets " or software tools primarily used by programmers." I've used sftp for decades, as a programmer. This question should be reopened.Abutment
@Abutment - I've used cars for decades, and I'm a programmer. That doesn't make an ignition issue an Stack Overflow problem. sftp clearly sits in the realm of Unix & Linux and Super User.Scientific
J
15

"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 way 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
Jespersen answered 11/5, 2018 at 11:59 Comment(0)
C
3

It can be fixed by using the internal-sftp subsystem. Edit /etc/ssh/sshd_config and replace

Subsystem sftp /usr/lib/openssh/sftp-server

by

Subsystem sftp internal-sftp

Then you need to restart sshd service with this command:

/bin/systemctl restart sshd.service
Cavalier answered 21/7, 2021 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.