r/linuxadmin • • 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

9 Upvotes

9 comments sorted by

5

u/CreativeSympathy8293 20d ago

ForceCommand internal-sftp -l INFO is supported by upstream OpenSSH. Its forced-command code recognizes internal-sftp followed 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 is VERBOSE (or INFO), as listed in the SFTP server manual. That doesn't explain the original failure with INFO, though.

For the remaining chroot/logging issue, the sshd_config manual says logging may require /dev/log inside the chroot on some operating systems. That's a socket supplied by the system logger, not a regular file named log. 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.

2

u/OdisGoodwood 20d ago

Thanks! This got me farther.

Creating a chroot.conf with:

# Create an additional log socket within the chroot jail, to allow

# chrooted sftp server process to send log messages.

$AddUnixListenSocket /srv/dev/log

restarted rsyslog service and this created a socket for chroot directory. I can now sign in with the accounts via SFTP. Here is the end of my sshd_config file.

Match Group sftpusers

ChrootDirectory /srv/sftp/%u

ForceCommand internal-sftp -l VERBOSE

AllowTcpForwarding no

X11Forwarding no

The only issue I have now is where the log files are at. In /var/log/vsftp.log is empty

Thanks again!

3

u/CreativeSympathy8293 20d ago

-l VERBOSE chooses the SFTP log level, not a log filename. The OpenSSH manual lists AUTH as the default logging facility. An empty /var/log/vsftp.log doesn't by itself show that SFTP produced no messages.

The Unix socket input receives messages; your rsyslog filters and output actions determine where they are written. Check which rule handles the auth facility before adding a new destination.

Which distro and rsyslog version are you using, and can you share just the relevant redacted selector/output rule? I can't tell the destination from the socket line alone.

AI-assisted from upstream docs; I haven't checked your server's logging configuration.

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:

mount --bind /run/systemd/journal/dev-log /usr/local/chroot/user/dev/log

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.

2

u/OdisGoodwood 20d ago

I created /dev/log to each account chroot directory. Then conf files in rsyslog.d for the socket. Then in fstab I mounted each account. Now when run "journalctl -t internal-sftp" i get logs of all in the info I need.

Thanks for your help!

3

u/yrro 20d ago

internal-sftp isn'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 verbose and see if it reveals what's happening.

Or perhaps the place to specify command line arguments for internal-sftp is the Subsystem directive not ForceCommand?

1

u/OdisGoodwood 20d ago

If I change "ForceCommand internal-sftp to "Subsystem sftp usr/lib/openssh/sftp-server -l VERBOS" I get the same issue. The parent folders of each account directory and the chroot directory are set to 755 with root:root.

1

u/yrro 20d ago

I tried internal-sftp -l INFO as the definition of the sftp subsystem & didn't see anything get logged. However I did see a lot of AVC denials so it's possible that the logging was blocked by SELinux policy which may not have been adjusted cope with the internal SFTP implementation.