Linux SFTP – Use .bashrc Without Breaking SFTP

bashrclinuxsftpssh

My problem is that I need to set a few variables, and output a few lines every time I login to the ssh shell, and at the same time I have to be able to use sftp to tarnsfer files via Filezilla.

Now, as per the openssh FAQ at http://www.openssh.org/faq.html, if your startup scripts echo any kind of output, it messes up with sftp. So it either delays indefinitely, or errors out with a "Connection closed by server with exit code 128".

I have tried solutions like moving .bashrc to .bash_profile, or using the following code in .bashrc:

if [ "$TERM" != "dumb" ]
then
   source .bashc_real
fi

And:

if [ "$TERM" = "xterm" ]
then
   source .bashc_real
fi

However, nothing works. My shell terminal is bash, and I connect to sftp with filezilla.

Best Answer

Try doing this instead

if [ "$SSH_TTY" ]
then
   source .bashc_real
fi