摘自:https://www.jianshu.com/p/f24d8ca565d7
一、問題
為什么有兩種方法可以使用OpenSSH設置SFTP以及何時使用哪種方法? 它們之間有什么區別嗎?
我的意思是第一個使用OpenSSH的lib,第二個使用“使用內部”,所以它也屬於OpenSSH?

二、解答
sftp-server和internal-sftp都是OpenSSH的一部分。
sftp-server是一個獨立的二進制文件, internal-sftp只是一個配置關鍵字,告訴sshd使用內置sshd的SFTP服務器代碼,而不是運行另一個進程(通常是sftp-server)。
從功能的角度來看,sftp-server和internal-sftp幾乎完全相同。 它們是使用相同的源代碼構建的。
internal-sftp的主要優點是,當與ChrootDirectory指令一起使用時,它不需要任何支持文件。
sshd_config(5)手冊頁:
對於Subsystem指令:
指定sftp-server實現SFTP文件傳輸子系統或者internal-sftp實現進程內SFTP服務,這可以簡化使用ChrootDirectory強制配置以在客戶端上強制使用不同的文件系統root的配置。
對於ForceCommand指令:
指定internal-sftp命令將強制使用與ChrootDirectory一起使用時不需要支持文件的進程內SFTP服務。
對於ChrootDirectory指令:
ChrootDirectory必須包含支持用戶會話所需的文件和目錄。對於交互式會話,這至少需要一個shell(通常是sh)和基本/ dev節點,例如null,zero,stdin,stdout,stderr和tty設備。對於使用SFTP的文件傳輸會話,如果使用進程內sftp服務器,則無需對環境進行其他配置,但使用日志記錄的會話可能需要在某些操作系統上的chroot目錄中使用/ dev / log(請參閱sftp-server以獲取細節)。
internal-sftp的另一個優點是性能,因為沒有必要為它運行新的子進程。
internal-sftp在很晚的時候被添加(2008年的OpenSSH 4.9p1?),而不是獨立的sftp-server二進制文件,但它現在是默認的,我相信沒有理由將sftp-server用於新安裝。
sshd在遇到sftp-server時可以自動使用internal-sftp,因為功能相同而且internal-sftp甚至具有上述優點,但是在一些情況下,存在差異。
幾個例子:
1.管理員可能依賴登錄shell配置來阻止某些用戶登錄。切換到internal-sftp會繞過限制,因為不再涉及登錄shell。
2.使用sftp-server二進制文件(作為一個獨立的進程),你可以使用一些hacks,比如在sudo下運行SFTP。
3.對於SSH-1(如果有人仍在使用它),則根本不涉及Subsystem指令,使用SSH-1的SFTP客戶端明確告知服務器,服務器應運行什么二進制文件。 因此,傳統的SSH-1 SFTP客戶端具有硬編碼的sftp服務器名稱。
三、參考
How to log internal-sftp chroot jailed users?
https://access.redhat.com/discussions/672633
SFTP chroot
https://wiki.archlinux.org/index.php/SFTP_chroot
How do I change user after login (e.g. su root)?
https://winscp.net/eng/docs/faq_su#sudo
OpenSSH的SFTP服務器設置
https://caibaoz.com/blog/2013/04/27/sftp_config_for_openssh
OpenSSH:internal-sftp和sftp-server之間的區別
https://codeday.me/bug/20181105/355509.html
OpenBSD manual page server
https://man.openbsd.org/sftp-server
sftp-server(8) - Linux man page
https://linux.die.net/man/8/sftp-server
Which internal-sftp options are available?
https://superuser.com/questions/1114958/which-internal-sftp-options-are-available
How to Configure Chroot Environments for SFTP Access on Ubuntu 16.04?
OpenSSH: Difference between internal-sftp and sftp-server
https://serverfault.com/questions/660160/openssh-difference-between-internal-sftp-and-sftp-server/660325
Restricting Users To SFTP Plus Setting Up Chrooted SSH/SFTP
https://www.howtoforge.com/restricting-users-to-sftp-plus-setting-up-chrooted-ssh-sftp-debian-squeeze
SFTP Server Chroot Configuration
http://www.yolinux.com/TUTORIALS/SFTP-Server-Chroot-Configuration.html
SDB:SFTP server with Chroot
https://en.opensuse.org/SDB:SFTP_server_with_Chroot
Logging sFTP activity for chrooted users
https://www.the-art-of-web.com/system/sftp-logging-chroot
How to set the sftp -s subsystem option in a configuration file?
https://unix.stackexchange.com/questions/32307/how-to-set-the-sftp-s-subsystem-option-in-a-configuration-file