
我有一台 Ubuntu 18.04 伺服器並安裝了 vsftpd。
我按照本教學創建了一個新的 FTP 用戶:https://devanswers.co/installing-ftp-server-vsftpd-ubuntu-18-04/
我想將用戶鎖定到該資料夾:/var/www/html/mydomain.com/
但無論我在/etc/vsftpd.conf
文件中設定什麼,我都無法做到。
例如,我嘗試了以下建議:
write_enable=YES
local_umask=022
chroot_local_user=YES
allow_writeable_chroot=YES
我還嘗試添加:
local_root=/
或者
local_root=/var/www/html/mydomain.com/
用戶可以成功登錄,但我無法將其鎖定到任何資料夾。任何建議都會很棒。謝謝。
答案1
經過幾個小時的搜索,我自己找到了答案:
在終端機中運作:
sudo nano /etc/ssh/sshd_config
在文件末尾添加:
Match User yourusername
ForceCommand internal-sftp
PasswordAuthentication yes
ChrootDirectory /var/www/html/yourdomain.com/
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
將 yourusername 替換為您建立的 ftp 使用者的名稱,並取代 ChrootDirectory 路徑。
在終端機中運作:
sudo systemctl restart sshd
更多詳細資訊請參閱此處:https://www.digitalocean.com/community/tutorials/how-to-enable-sftp-without-shell-access-on-ubuntu-18-04