SFTP將用戶登錄限制在某一個目錄

sftp將W用戶登錄限制在/file/w目錄

(1)添加用戶並且設置密碼
useradd -d /w -s /bin/false W
passwd W

(2)修改/etc/ssh/sshd_config文件
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp

Match User W
ChrootDirectory /file/
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp

(3)修改權限並且檢查
chmod -R 755 /file/w
chown root:root /file
ll -ld /file/w/
drwxr-xr-x. 3 root root 21 Aug 8 09:51 /file/w/

(4)重新啓動sshd服務
systemctl restart sshd

(5)在本地進行測試
sftp W@localhost
W@localhost's password:
Connected to localhost.
sftp> pwd
Remote working directory: /w
sftp> cd ..
sftp> pwd
Remote working directory: /
sftp> exit

注意:在clinet登錄後, 提示沒有權限, 請檢查server端是否開了selinux, 如果開啓selinux, 可以將其關閉後, 再次重啓sshd服務

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章