0% found this document useful (0 votes)
182 views8 pages

Bashrc - SFTP Gives An Error Received Message Too Long and What Is The Reason - Unix & Linux Stack Exchange

This document discusses why the sftp command may return the error "Received message too long" when connecting to a remote server. Several potential causes and solutions are provided: 1) Printing anything to stdout in initialization files like .bashrc can interfere with the sftp protocol and cause this error. These files need to be silent for non-interactive sessions. 2) Using the "internal-sftp" subsystem instead of the default sftp server may avoid reading initialization files and resolve the issue. 3) Adding a check for interactive sessions to .bashrc and exiting early if not interactive prevents extraneous output.

Uploaded by

Alvur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
182 views8 pages

Bashrc - SFTP Gives An Error Received Message Too Long and What Is The Reason - Unix & Linux Stack Exchange

This document discusses why the sftp command may return the error "Received message too long" when connecting to a remote server. Several potential causes and solutions are provided: 1) Printing anything to stdout in initialization files like .bashrc can interfere with the sftp protocol and cause this error. These files need to be silent for non-interactive sessions. 2) Using the "internal-sftp" subsystem instead of the default sftp server may avoid reading initialization files and resolve the issue. 3) Adding a check for interactive sessions to .bashrc and exiting early if not interactive prevents extraneous output.

Uploaded by

Alvur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

bashrc - sftp gives an error: "Received message too long" and what is th... about:reader?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Funix.stackexchange.com%2Fquest...

unix.stackexchange.com

sftp gives an error: "Received


message too long" and what
is the reason?
Peter ScottPeter Scott 53944 silver badges33 bronze
badges
6-8 minutes

I was able to do sftp yesterday to a RHEL 5.4 box


(RedHat) and today I can't.

The message is "Received message too


long 778199411", and after some investigation,
it was due to my RHEL box's .bashrc having a
line echo "running .bashrc" -- or echoing
anything at all, I think.

So why would printing out a line affect sftp? It felt


a bit like a design issue as printing out a line in
.bashrc works in other situations such as log in

1 of 8 05/10/2022, 18.58
bashrc - sftp gives an error: "Received message too long" and what is th... about:reader?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Funix.stackexchange.com%2Fquest...

or ssh and it is kind of hard to track down when


sftp fails for such a weird reason.
So the question is, why printing out a line cause
such error and what if we still like to print out
something in .bashrc? (mainly to see when this
file get sourced/executed).
asked Jan 17, 2013 at 4:38

nonopolaritynonopolarity
2,7815 gold badges26 silver badges38 bronze
badges
2
This is a longstanding problem. I found it ten years
ago when I first had to mix commercial SSH at
work and open-SSH at home. I ran into it again
today and found this post.
If I had searched for "sftp/scp fails but ssh is OK" I
would have been reminded of the solution sooner!

Put simply, .bashrc, .bash_profile, .cshrc,


.profile, etc., have to be silent for non-

2 of 8 05/10/2022, 18.58
bashrc - sftp gives an error: "Received message too long" and what is th... about:reader?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Funix.stackexchange.com%2Fquest...

interactive sessions or they interfere with the sftp /


scp connection protocol. 
This output confuses the sftp/scp client.  You can
verify if your shell is doing this by executing:
ssh yourhost /usr/bin/true
If the above command produces any output, then
you need to modify your shell initialization.
From the open-SSH FAQ: 2.9 - sftp/scp fails at
connection, but ssh is OK.

answered Jul 23, 2013 at 16:29

4
At least for SFTP this can be fixed by using the
internal-sftp subsystem, as that does not
read .bashrc or /etc/motd.

Simply change the /etc/ssh/sshd_config file


and change the SFTP subsystem:

#Subsystem sftp /usr/lib/openssh


/sftp-server

3 of 8 05/10/2022, 18.58
bashrc - sftp gives an error: "Received message too long" and what is th... about:reader?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Funix.stackexchange.com%2Fquest...

Subsystem sftp internal-sftp


And the error is gone.
answered Dec 1, 2016 at 9:31

KennethKenneth
3793 silver badges3 bronze badges
4
just put following into top of ~/.bashrc on username
of id on remote machine if that id uses bash

# If not running interactively, don't


do anything and return early
[[ $- == *i* ]] || return
which simply exits early from the ~/.bashrc instead
of sourcing entire file ... this solves making .bashrc
silent when you are not logging into that id and are
just running your scp or sftp with that username as
the remote id ... to quote @Peter Scott in other
answer : "Put simply, .bashrc and .bash_profile etc
have to be silent or they interfere with the sftp / scp
connection protocol."

4 of 8 05/10/2022, 18.58
bashrc - sftp gives an error: "Received message too long" and what is th... about:reader?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Funix.stackexchange.com%2Fquest...

Alternatively, if that remote id uses zsh then put


following at top of its ~/.zshrc

# If not running interactively, don't


do anything and return early
[[ -o interactive ]] || exit 0
If the shell on your remote machine does not use
~/.bashrc then make above edit in file
~/.bashrc_profile or ~/.profile or similar to suit your
shell on that remote box
.... UPDATE ... by putting above snippet into top of
file ~/.bashrc for user on remote box any ssh
connection will source file ~/.bashrc which will
simply read ~/.bashrc until is sees this snippet then
stop continuing to source the remainder of file
~/.bashrc so as to avoid polluting the shell on that
remote box with things ssh connection does not
need nor want ... do NOT put snippet into any file
which must get sourced or executed to completion
as the point of this snippet is to exit early from
sourcing file ~/.bashrc ( NOTE there is a difference
between sourcing a file versus executing a file ) ...
file ~/.bashrc is always sourced never executed

5 of 8 05/10/2022, 18.58
bashrc - sftp gives an error: "Received message too long" and what is th... about:reader?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Funix.stackexchange.com%2Fquest...

answered Mar 11, 2019 at 14:13

Scott StenslandScott Stensland


2,3832 gold badges22 silver badges22 bronze
badges
7
Every response I've seen anywhere on this all
claim it is too much printed output via /etc/motd,
or .bashrc, etc. Not always true. If you have an
account that has no .bashrc, the /etc/motd is
empty, and the default .bashrc is minimal with no
printed output YOU CAN STILL have the problem.
If you have a user account with a shell of
/sbin/nologin or /bin/false this error will
still happen.
Why would you do this??? If you were trying to
grant someone root-jailed sftp, with no secure-
shell access this will happen.

Work around: allow ssh and put them in a root jail


as well. This is a problem that needs to be
addressed in ssh, it's far too long in coming.

6 of 8 05/10/2022, 18.58
bashrc - sftp gives an error: "Received message too long" and what is th... about:reader?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Funix.stackexchange.com%2Fquest...

Jakuje
20.4k7 gold badges49 silver badges68 bronze
badges
answered Dec 13, 2015 at 22:03

3
There can be one more reason. On RHEL 6 with
openssh-5.3p1-122.el6.x86_64 we have found,
that it behaves wrong when LOCALE remains at
"C". When changed with:

export LC_ALL="en_US.UTF-8"
Then sftp behaves correctly. In the previous
openssh-5.3p1-118 we haven't experienced such a
behaviour so it's probably some minor bug in this
build.
answered Aug 8, 2017 at 13:22

Jaroslav KuceraJaroslav Kucera


9,0075 gold badges13 silver badges27 bronze

7 of 8 05/10/2022, 18.58
bashrc - sftp gives an error: "Received message too long" and what is th... about:reader?url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Funix.stackexchange.com%2Fquest...

badges
1
In my case, to make it work, I needed to disable
Ubuntu's welcome message.

answered Aug 9, 2017 at 11:16

8 of 8 05/10/2022, 18.58

You might also like