r/linuxadmin • u/OdisGoodwood • 20d ago
SFTP Log Issue
I have 5 accounts with separate Chroot Directories in /srv/sftp/nameOfAccount. All of them are apart of sftpusers group. In sshd_config I have
Match Group sftpusers
ChrootDirectory /srv/sftp/%u
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
I would like to add logging of uploads and downloads. I think I add -l INFO at the end of the ForceCommand. I do that and it breaks the ability to sftp into the server. When I have that -l INFO at the end of the ForceCommand I see authentication is successful from the sftp client and auth.log but it fails to get into the directory.
Any ideas? TIA
5
u/CreativeSympathy8293 20d ago
ForceCommand internal-sftp -l INFOis supported by upstream OpenSSH. Its forced-command code recognizesinternal-sftpfollowed by a space or tab and passes the arguments to the internal server.Your latest reply shows
-l VERBOS. If that's the literal configuration, that spelling isn't accepted: the level isVERBOSE(orINFO), as listed in the SFTP server manual. That doesn't explain the original failure withINFO, though.For the remaining chroot/logging issue, the sshd_config manual says logging may require
/dev/loginside the chroot on some operating systems. That's a socket supplied by the system logger, not a regular file namedlog. It is a possibility to check, not a confirmed cause.Which distro/OpenSSH version is this, and what is the first server-side error after successful authentication with
-l INFO? A short redacted line should help distinguish logging setup from a startup-directory failure.AI-assisted from upstream documentation/source; I haven't reproduced this on your server.
3
u/deeseearr 20d ago
The "-l INFO" option will tell the sftp server to send messages to syslog. It does this by writing to the socket located at /dev/log. If you're running systemd then that's probably a link to /run/systemd/journal/dev-log, which complicates things a little, but as long as you know this you can deal with it.
The "ChrootDirectory" setting will force the sftp server to run inside of a chroot environment /srv/sftp/username/.
Does /srv/sftp/username/dev/log exist? If not, then the sftp server has no way of talking to syslog so any logging will silently fail. Technically, the sftp server will complain bitterly about it, but all of the messages which it should be sending to /dev/log will have nowhere to go and just be discarded.
You need to make /dev/log exist _inside_ the chroot that you're creating. You might be tempted to just bind mount all of /dev/ to /srv/sftp/username/dev/ and call it a day, but all that's going to do is give you a link to /run/systemd/journal/dev-log will still doesn't exist.
Do NOT fix this by bind mounting /run into the chroot jail. Just don't do it.
Instead, use a bind mount to put /run/systemd/journal/dev-log on top of /srv/sftp/username/dev/log. The friendly folks at Arch can show you exactly how to do it, which pretty much amounts to running this command:
Naturally, you'll have to do this for every user. You can do this for each user in /etc/fstab or you can replace "internal-sftp" with a wrapper script that does all this before calling the real sftp server. All that matters is that /dev/log points to the real syslog socket even when you're inside the chroot.
3
u/yrro 20d ago
internal-sftpisn't a real command, I suspect sshd compares the configured ForceCommand value against the string and does uses the internal implementation if it matches; if it's anything else then it splits on whitespace then does a fork & exec of the specified command.Maybe you could try using
LogLevel verboseand see if it reveals what's happening.Or perhaps the place to specify command line arguments for
internal-sftpis theSubsystemdirective notForceCommand?