SFTP exits after a few seconds

When connecting via a SFTP client like Filezilla, if you experience a short delay and then disconnection, this is most likely an issue caused by your .bashrc 

During SFTP connections, your .bashrc will be evaluated just as if you were logging in via SSH. If you've added anything to your .bashrc that attempts to echo to the terminal/standard out, this will cause your SFTP client to hang and then disconnect.

You can either remove the statement in your .bashrc that is writing output (an echo statement, a call to an app or module that sends a message to standard out, etc.) -or- you can put the offending statement into an evaluation clause that first checks to see if this is a interactive login, like so:

if [ “$SSH_TTY” ]
     echo “SFTP connections won’t evaluate the things inside this clause."
     echo "Only real login sessions will.”

Posted in: a. Login and Authentication