Linux 限制SFTP用戶只能訪問某個目錄
1. 新建用戶並設置密碼
> useradd suser
> passwd suser // 輸入密碼
2. 設置sshd配置文件
> cd /etc/ssh/
> cp sshd_config sshd_config.back // 備份
> vi sshd_config
// 注釋該行 不注釋的話會報錯
#Subsystem sftp /usr/libexec/openssh/sftp-server
#這行指定使用sftp服務使用系統自帶的internal-sftp
Subsystem sftp internal-sftp
#這行用來限制四川CA,不允許訪問其他目錄
Match User ca
#用chroot將用戶的根目錄指定到 /home/ca,這樣用戶就只能在 /home/ca下活動
ChrootDirectory /home/ca
#這行用來匹配用戶
Match User userkj
#用chroot將用戶的根目錄指定到/home/userkj,這樣用戶就只能在/home/userkj下活動
ChrootDirectory /home/userkj
#其他用戶繼續添加......
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
3. 重啟sshd服務
> service sshd restart
>systemctl restart sshd
已經成功實現了Linux 限制SFTP用戶只能訪問某個目錄。
2. 重啟sshd時報錯:Starting sshd: /etc/ssh/sshd_config line 141: Subsystem 'sftp' already defined.
原因:忘記把Subsystem注釋,導致/etc/ssh/sshd_config同時存在有兩個Subsystem節點
