在Debian系統中,要限制SFTP用戶的訪問目錄,可以使用chroot
功能。以下是配置步驟:
sudo apt-get update
sudo apt-get install openssh-server
sudo groupadd sftp_users
sftp_users
組:sudo useradd -m -G sftp_users your_username
sudo passwd your_username
/etc/ssh/sshd_config
文件,找到或添加以下內容:# 在文件末尾添加以下內容
Match Group sftp_users
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
這里,ChrootDirectory %h
表示將用戶的根目錄限制在其主目錄中。ForceCommand internal-sftp
表示僅允許SFTP連接。AllowTcpForwarding no
和X11Forwarding no
禁用了TCP和X11轉發。
uploads
的目錄,并將其所有權更改為新用戶:sudo mkdir /home/your_username/uploads
sudo chown your_username:sftp_users /home/your_username/uploads
sudo systemctl restart ssh
現在,新用戶應該只能訪問其主目錄和uploads
目錄。請注意,這些步驟可能需要根據您的具體需求進行調整。