So…
I’m setting up one of my new VPSes (Linode Rocks!) and I was having a weird thing where I could ssh in with root, but not sftp. Other users could do both just fine.
The connection would be made, I tried the usual ssh -vvv type things to get the debugging info, but it looked like the connection was just fine.
Finally, after digging around for a couple of hours and trying every configuration change I (and all the nice people on #linode) could think of, I found this:
OpenSSH FAQ (Frequently asked questions)
2.9 – sftp/scp fails at connection, but ssh is OK.
sftp and/or scp may fail at connection time if you have shell initialization (.profile, .bashrc, .cshrc, etc) which produces output for non-interactive sessions. 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.
I had just added some things to my .bashrc, like, for example:
bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward'
A quick call to:
# ssh root@myhost /usr/bin/true
confirmed that those two commands were failing in an SFTP session like so:
# ssh root@myhost /usr/bin/true /root/.bashrc: line 18: bind: warning: line editing not enabled /root/.bashrc: line 19: bind: warning: line editing not enabled bash: /usr/bin/true: No such file or directory
I couldn’t remember which was which (.bash vs. .bash_profile) so a quick Google search turned up this post.
I moved those two statements to .bash_profile, and sftp now works just fine…
Well, that was fun…