Linux(CentOS 6/7)搭建 vsFTPD 服务器及排错实战(SELinux 导致无法切换目录)
环境说明
虚拟机系统版本为CentOS 7,IP地址配置为静态IP(如192.168.1.100),确保网络连通性正常。
安装 vsFTPD
方法一:通过yum安装vsftpd服务:
[root@localhost Packages]# yum install -y vsftpd验证安装是否成功:
[root@localhost Packages]# rpm -qa | grep vsftpd方法二:使用rpm-ivh命令安装vsftpd
[root@localhost Packages]# rpm -ivh vsftpd-2.2.2-11.el6.x86_64.rpm配置 vsFTPD
编辑配置文件/etc/vsftpd/vsftpd.conf,修改以下关键参数:
anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES banner_file=/etc/vsftpd/welcome xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES保存后重启服务使配置生效。
启动服务并设置开机自启
启动vsftpd服务并设置开机自启:
[root@localhost ~]# service vsftpd start [root@localhost ~]# chkconfig vsftpd on创建本地用户
使用useradd创建FTP专用用户(如ftpuser),并设置密码:
[root@localhost ~]# useradd sdcet [root@localhost ~]# passwd sdcet密码可以用:sdcet@123
修改主配置文件
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf配置内容如下:
anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES banner_file=/etc/vsftpd/welcome xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES重启FTP服务
[root@localhost ~]# service vsftpd restart客户端测试
(1)安装FTP客户端工具
[root@dns Packages]# rpm -ivh ftp-0.17-53.el6.x86_64.rpm(2)准备测试文件
在服务器端用户主目录下创建下载测试文件:
[root@localhost ~]# touch /home/sdcet/1在本地创建上传测试文件
[root@localhost ~]# touch q(3)登录 FTP 服务器并测试
在登录之前,需要先把服务器的 IP 改成192.168.0.100:
[root@localhost ~]# ifconfig eth0 192.168.0.100 netmask 255.255.255.0[root@localhost ~]# ftp 192.168.0.100交互过程:
Connected to 192.168.0.100 (192.168.0.100). 220 Name (192.168.0.100:root): sdcet 331 Please specify the password. Password: 230 Login successful. ftp> get 1 /home/1 local: /home/1 remote: 1 227 Entering Passive Mode (192,168,2,10,167,77). 150 Opening BINARY mode data connection for 1 (0 bytes). 226 Transfer complete. ftp> put q q local: q remote: q 227 Entering Passive Mode (192,168,2,10,59,234). 150 Ok to send data. 226 Transfer complete. ftp> bye问题排错
500 OOPS:cannot change directory:/home/sdcet
检查SELinux 状态
getenforce如果显示Enforcing,SELinux 可能在阻止 vsftpd。
解决方案:
#方法一:临时关闭 SELinux [root@localhost ~]# setenforce 0 #方法二:永久关闭 SELinux(不推荐,但省事) [root@localhost ~]# vim /etc/selinux/config #把 SELINUX=enforcing 改为: SELINUX=disabled [root@localhost ~]# reboot #重启