Why are there two ways to setup SFTP with OpenSSH and when to use which? Is there any difference between them?
I mean the first one is using a lib from OpenSSH and the second one says "use the internal", so it is also OpenSSH?
Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
Both
sftp-server
andinternal-sftp
are part of OpenSSH. Thesftp-server
is a standalone binary. Theinternal-sftp
is just a configuration keyword that tellssshd
to use the SFTP server code built-into thesshd
, instead of running another process (what would typically be thesftp-server
).The
internal-sftp
was added much later (OpenSSH 4.9p1 in 2008?) than the standalonesftp-server
binary. But it is the default by now. Thesftp-server
is now redundant and is kept probably for a backward compatibility.I believe there's no reason to use the
sftp-server
for new installations.From a functional point of view, the
sftp-server
andinternal-sftp
are almost identical. They are built from the same source code.The main advantage of the
internal-sftp
is, that it requires no support files when used withChrootDirectory
directive.Quotes from the
sshd_config(5)
man page:For
Subsystem
directive:For
ForceCommand
directive:For
ChrootDirectory
directive:Another advantage of the
internal-sftp
is a performance, as it's not necessary to run a new sub-process for it.It may seem that the
sshd
could automatically use theinternal-sftp
, when it encounters thesftp-server
, as the functionality is identical and theinternal-sftp
has even the above advantages. But there are edge cases, where there are differences.Few examples:
Administrator may rely on a login shell configuration to prevent certain users from logging in. Switching to the
internal-sftp
would bypass the restriction, as the login shell is no longer involved.Using the
sftp-server
binary (being a standalone process) you can use some hacks, like running the SFTP undersudo
.For SSH-1 (if anyone is still using it),
Subsystem
directive is not involved at all. An SFTP client using SSH-1 tells the server explicitly, what binary the server should run. So legacy SSH-1 SFTP clients have thesftp-server
name hard-coded.There exist alternative SFTP implementations that can be used together with OpenSSH:
You can lock an authorized_key to the external sftp-server.
When you do, your user can sftp, but cannot scp or ssh:
Attempting to do anything else will just hang:
Alas, there is no easy way for a key to be locked to a chroot unless the sshd_config is modified. This would be really cool for a user to be able to do without the intervention of the system manager.
If all you want to do is lock an account to use SFTP only, just give their account the default shell /sbin/nologin