[root@localhost ftp]# vim /etc/ssh/sshd_config
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
Match User dave
ChrootDirectory /opt/ftp/dave
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
重启ssh
4.测试访问
代码如下:
root@10.1.1.200:test# sftp -oPort=22 dave@10.1.6.175
Connecting to 10.1.6.175...
dave@10.1.6.175's password:
Read from remote host 10.1.6.175: Connection reset by peer
Couldn't read packet: Connection reset by peer
发现连接不上,查看日志
代码如下:
[root@localhost ftp]# tail /var/log/messages
Jan 6 11:41:41 localhost sshd[4907]: fatal: bad ownership or modes for chroot directory "/opt/ftp/dave"
Jan 6 11:41:41 localhost sshd[4905]: pam_unix(sshd:session): session closed for user dave
[root@localhost ftp]# ll
total 4
drwxr-xr-x 3 dave dave 4096 Jan 5 13:06 dave
[root@localhost ftp]# chown root:root dave
[root@localhost ftp]# chmod 755 dave
[root@localhost ftp]# ll
total 4
drwxr-xr-x 3 root root 4096 Jan 5 13:06 dave
然后在测试通过
代码如下:
root@10.1.1.200:test# sftp -oPort=22 dave@10.1.6.175
Connecting to 10.1.6.175...
dave@10.1.6.175's password:
sftp> ls
test
sftp> cd ..
sftp> ls
test
sftp> cd test
sftp> ls
1.txt
sftp> get 1.txt
Fetching /test/1.txt to 1.txt
/test/1.txt