In Ubuntu GNU/Linux 12.04, I have a user johndoe that is part of an sftponly group, set up to sftp to a chroot jail using
Subsystem sftp internal-sftp
Match Group sftponly
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
at the end of /etc/ssh/ssh_config. All components of the user's home directory are root-owned directories that are not writeable by any other user or group, as explained in man sshd_config (under ChrootDirectory). Inside his chroot jail, there is a writeable directory files:
sudo groupadd sftponly
sudo mkdir -p /home/sftponly/johndoe/files
sudo useradd -d /home/sftponly/johndoe -g sftponly -s /usr/sbin/nologin johndoe
sudo chmod go-w /home/sftponly/{,johndoe}
sudo chown johndoe:sftponly /home/sftponly/johndoe/files
sudo chmod ug+rwX /home/sftponly/johndoe/files
(Setting the shell to /bin/false did not work with either ssh or sftp. With nologin as the shell ssh connects, shows "MOTD", and then disconnects, which is the expected behavior.)
But sftp fails with the message Received message too long 1416128883. I know this failure is caused by "MOTD" (Message Of The Day), as sftp expects a "clean login." I have tried disabling all "MOTD" pieces on the server using the following, with (these results):
Adding
PrintLastLog noandPrintMotd noto the end of/etc/ssh/ssh_configand restartingsshusingrestart ssh. (No effect. Testing withsshshows both "MOTD" and "Last Login:".)Commenting out
session optional pam_motd.soin/etc/pam.d/sshd. (Prevents MOTD. But there is no corresponding entry for "LastLog" so, testing withssh, "Last Login:" still shows up and hencesftpstill fails.)Commenting out
session optional pam_lastlog.soandsession optional pam_motd.soin/etc/pam.d/login. (No effect. Testing withsshshows both MOTD and "Last Login:".)Creating the
.hushloginfile on the client usingtouch ~/.hushlogin. (No effect.)
I am out of ideas. Where else may this "Last Login:" message be coming from and how can it be disabled (ideally only for sftp and not for ssh logins, but, I imagine as sftp uses ssh, the message is going to be there either for both or none)?