0

Question

When I start SSH server, my Debian automatically start the SFTP server as well - why is it design in such way?

Environment:

  • Linux 5.10.0-14-amd64 Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux
  • ssh.service - OpenBSD Secure Shell server

Background

Today I realized:

  • when I want to handle http requests, I start a web server - Apache(2), Node.js, etc.
  • when I want to handle SSH, I start an SSH server
  • when I want to handle SFTP... Debian already started SFTP server for me

So I researched, and according to this post 378313/default-sftp-server-in-debian-9-stretch, I found out SFTP is started as "part of (Open)SSH" which makes perfect sense but also feels strange for reasons such as separation of concerns.

Unlike Windows, I have never felt Debian doing something unexpected or extra on my behalf. But today I felt it - after all I said systemctl restart ssh, not systemctl restart ssh-and-also-ftp (the latter command is made-up).

As I am new to Unix/Linux and its philosophy, I would appreciate if there are any good explanations for this situation.

3 Answers 3

1

SFTP is built-in to the SSH protocol and therefore the SSH server.

You can disable the functionality on the server if it's not required by changing /etc/ssh/sshd_config so that you remove the Subsystem line corresponding to the sftp-server.

For example, this line defines an external sftp-server utility to handle the SFTP service:

Subsystem sftp-server

This line defines an internal implementation of the SFTP service:

Subsystem internal-sftp

Removing or commenting out the Subsystem line will disable the SFTP service entirely.

# Subsystem …

Remember that tools such as scp and rsync (if it's installed) will still function, though, so disabling SFTP will not of itself prevent users from transferring files between client and server.

3
  • This solution (removing or commenting out the Subsystem line of sshd_config) will not work in Debian based systems including Ubuntu because these have a compiled-in default of Subsystem sftp /usr/lib/openssh/sftp-server (see man sshd_config). For these systems, see my answer.
    – Juergen
    Sep 14 at 12:59
  • @Juergen you and I must have different versions of Debian. I have just retested (this time on bullseye) and if I comment the Subsystem … line the service is disabled. The precise error returned to the client is subsystem request failed on channel 0 Sep 14 at 13:12
  • My experience was from an old Ubuntu 16 system where commenting out the subsystem line, reloading the ssh service and killing the sftp-server process caused it to respawn. Added some details to my answer.
    – Juergen
    Sep 14 at 13:25
0

To disable the built-in sftp server of sshd on Debian based systems including Ubuntu, it is not sufficient to remove or comment out the Subsystem line of sshd_config because these systems have a compiled-in default of Subsystem sftp /usr/lib/openssh/sftp-server (see man sshd_config).

I had success disabling SFTP with this line in sshd_config instead in an yet old Ubuntu 16 system:

Subsystem sftp /bin/false

followed by systemctl reload ssh; killall sftp-server.

Citation from man sshd_config (same text in Ubuntu 16 and Ubuntu 22):
"Note that the Debian openssh-server package sets several options as standard in /etc/ssh/sshd_config which are not the default in sshd(8):
(...)
Subsystem sftp /usr/lib/openssh/sftp-server"

-1

Oddly, the accepted answer here does not address the question asked.

why is it design in such way?

The SFTP Server in openssh is not a conventional daemon/server. An instance is run on demand when a ssh connection requesting SFTP starts.

ssh can do lots of things - designing it this way means that there's no overhead from the sftp-server when people are using ssh for other stuff. Similarly ssh is often used for providing a remote terminal session but it doesn't implement its own shell.

In addition to being more conservative with resources, it also simplifies development by making the system modular.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .