一、问题描述
ftp创建目录操作失败
二、问题解析
vsftpd相关配置是否正确?目录是否可以读写?防火墙是否允许ftp?SELinux是否允许ftp操作?
三、解决办法
1、修改vsftpd配置
查询vsftpd配置文件所在的目录,使用yum安装默认目录为/etc/vsftpd
[root@wrx tmp]# whereis vsftpd vsftpd: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz [root@wrx tmp]# vim /etc/vsftpd/vsftpd.conf
有指定ftp上传根目录,因此需在配置文件中增加local_root=/var/www/html,chroot_local_user=YES如果已经存在,看看是否有没有被注释掉,如果有则将#去除,修改完后保存
local_root=/var/www/html chroot_local_user=YES
2、修改ftp上传目录权限
[root@wrx tmp]# chmod -R 077 /var/www/html
3、防火墙设置
如果是在本地开发环境中,可以将防火墙关闭。如果是在发布环境中,可以修改防火墙规则
临时关闭防火墙【立即生效】
[root@wrx tmp]# service iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] [root@wrx tmp]# service iptables status iptables: Firewall is not running.
永久关闭防火墙【重启后生效】
chkconfig iptables off
ftp上传默认端口是21,修改/etc/sysconfig/iptables 文件,添加以下内容
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
4、SELinux设置
如果是在本地开发环境中,可以将SELinux关闭,如果是在发布环境中,可以修改SELinux规则
临时关闭SELinux【立即生效】
[root@wrx tmp]# setenforce 0
永久关闭SELinux【重启后生效】
修改/etc/sysconfig/selinux文件,将SELINUX=enforcing修改为SELINUX=disabled
[root@wrx tmp]# vim /etc/sysconfig/selinux
正式发布环境
查看SELinux状态,只查看ftp相关
[root@wrx tmp]# sestatus -b | grep ftp allow_ftpd_anon_write off allow_ftpd_full_access off allow_ftpd_use_cifs off allow_ftpd_use_nfs off ftp_home_dir off ftpd_connect_db off ftpd_use_fusefs off ftpd_use_passive_mode off httpd_enable_ftp_server off tftp_anon_write off tftp_use_cifs off tftp_use_nfs off
在出现的结果中可以看到如下
ftp_home_dir off ftpd_disable_trans off
将其置为on,两个中任意一个置为on即可
ftp_home_dir on ftpd_disable_trans on
[root@wrx tmp]# setsebool -P ftpd_disable_trans on 或者 [root@wrx tmp]# setsebool -P ftp_home_dir on
修改完后重启vsftpd
[root@wrx tmp]# service vsftpd restart