我可能遺漏了一些非常明顯的東西,但是是否可以指定使用者可以透過 SFTP 存取的資料夾清單(而不僅僅是使用者主目錄)?
例如
Admin -> Full root access
WebDev1 -> Access to the primary vhost folder and sub directories
SysAdmin1 -> Access to all folders, except the vhost folder
Manager1 -> Access to vhost folder, and phpMyAdmin install folder
我可以讓它對「Admin」和「WebDev1」使用者正常工作,但對其他 2 個使用者則不行。
對於“Manager1”用戶,我希望允許訪問(包括子目錄):
/data/vhosts
/usr/share/phpMyAdmin
這是在使用 SSHD 的 Centos 7 系統上。我將不勝感激任何有關此問題的幫助,因為它已經讓我困惑了好幾個小時。
答案1
與你想做的事情相關的關鍵字是SFTP chroot 監獄
您需要修改您的 sshd_config,首先取消註解該行以啟用 SFTP,這將對應於以下內容:
Subsystem sftp /usr/lib64/ssh/sftp-server
在 sshd_config 的底部,模板中可能有以下一些被註解掉的內容。你會特別想要這樣的東西:
# jail only user dave to folder /dave_sftp/
Match User dave
ChrootDirectory /dave_sftp
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp
# jail only user ron to folder /ron_sftp/
Match User ron
ChrootDirectory /ron_sftp
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp
# jail users that are in group sftp1_group to the folder /sftp1_group/
Match Group sftp1_group
ChrootDirectory /sftp1_group
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp
# jail users that are in group sftp2_group to the folder /sftp2_group/
Match Group sftp2_group
ChrootDirectory /sftp2_group
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp
將特定使用者限製到特定資料夾相當簡單。根據你的問題指定不同使用者可以存取的資料夾列表,這只是您的一些手工勞動,創建一個單獨的群組並將其與您想要使用的特定資料夾相匹配,然後將這些用戶放入與您想要向他們提供監獄sftp 的資料夾相匹配的相關組中進入。例如,將使用者dave
放入 和 的兩個群組中sftp1_group
,sftp2_group
以允許該使用者存取多個資料夾。
一個非常好的例子也可以在這裡找到: https://serverfault.com/questions/591781/creating-sftp-users-and-jailing-to-chroot-on-centos-user-authentication-error
注意
chroot 主目錄之前的所有資料夾都必須由 root 使用者擁有且只能寫入。資料夾不能為群組可寫入 - 即使該群組是根組
這是另一個例子:https://askubuntu.com/questions/261663/how-can-i-set-up-sftp-with-chrooted-groups