将如下行用#注释 Subsystem sftp /usr/libexec/openssh/sftp-server 添加以下内容 Subsystem sftp internal-sftp Match User sftp #指定sftp登录访问目录 ChrootDirectory /data/sftp/%u X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp
2.2 重启ssh服务
1
systemctl restart sshd
三、测试与常用命令
3.1 验证sftp
1 2 3
sftp 用户名@ip #如果不是默认22端口,需要指定端口 sftp -P port 用户名@ip
3.2 上传
1 2 3 4 5 6 7 8
#上传一个本地文件到远程目录 put local-file [remote-file] #上传一个本地目录到远程目录 put -r local-dir [remote-file] #上传多个本地文件(支持通配符*)到远程目录 mput local-files [remote-file] #上传多个本地目录(支持通配符*)到远程目录 mput -r local-files [remote-file]
3.3 下载
1 2 3 4 5 6 7 8
#下载远程文件到本地目录 get remote-file [local-file] #下载远程目录到本地目录 get -r remote-dir [local-file] #下载多个远程文件(支持通配符*)到本地目录 mget remote-files [local-file] #下载多个远程目录(支持通配符*)到本地目录 mget -r remote-dirs [local-file]
3.4 远程常规命令执行
1 2 3 4 5 6
#远程文件 rm [remote-files] #进入远程目录 cd remote-directory #修改远程文件属性 chmod mode file-name