Having spent most of the morning building a LAMP server from scratch (or at least from a canned Linode job), I hit an SFTP problem that kept biting me.
The issue is that when trying to make an SFTP connection, it’s persistently refused despite the user account able to log into the server using SSH without any problem. The auth log doesn’t help much - you’ll see things like:
sshd[xxx]: Accepted password for root from XXX.XXX.XXX.XXX port 49926 ssh2 sshd[xxx]: pam_unix(sshd:session): session opened for user root by (uid=0) sshd[xxx]: subsystem request for sftp sshd[xxx]: pam_unix(sshd:session): session closed for user root
The problem (at least in my case) stemmed from a typo in the .bash_rc profile - there was a stray ‘fi’ which had crept in somewhere along the line. Logging into a shell and tailing the logs shows up the error - but there’s no trace when logging in via SFTP as it fails silently. Correct the error with the profile file, and SFTP then starts to work without problems.