在/etc/ssh/sshd_config 增加以下的内容
Subsystem sftp internal-sftp #使用sshd自带的sftp功能,不用外部sftp-server命令
Match User testsftponly # Match指令主要用于条件匹配。这里匹配用户,也可以指定Group
ChrootDirectory /data_sftp/ #限制sftp的起始目录,根据实验目录owner需要是 root root, 不指定这一行,起始目录为用户的主目录
X11Forwarding no # 禁止X11转发
AllowTcpForwarding no # 禁止tcp转发
ForceCommand internal-sftp # 限制用户除了能执行internal-sftp中允许的命令外,其他命令啥也执行不了
改完之后重启sshd服务, 即可生效。
参考
https://blog.csdn.net/gaotianyou/article/details/81236047
https://blog.csdn.net/xiaoxiao_yingzi/article/details/90446839
Man sshd_config
测试结果:
jiang@linux-8lq6:~> sftp testsftponly@192.168.255.138
Password:
Connected to 192.168.255.138.
sftp> ls
123.txt
sftp> get 123.txt
Fetching /home/testsftponly/123.txt to 123.txt
/home/te