1 安装vsftpd组件
[root@winy /]# find -name vsftpd.conf
./etc/vsftpd/vsftpd.conf
如果没有安装,那么再执行以下命令安装:
[root@winy /]# yum -y install vsftpd
安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件。
2 添加一个ftp用户
[root@winy ~]# useradd ftpuser
此用户就是用来登录ftp服务器用的。
这样一个用户建完,可以用这个登录,记得用普通登录不要用匿名了。登录后默认的路径为 /home/ftpuser.
3 给ftp用户添加密码。
[root@winy ~]# passwd ftpuser
输入两次密码后修改密码。
4 防火墙开启21端口
因为ftp默认的端口为21,而centos默认是没有开启的,所以要修改iptables文件
[root@winy ~]# vim /etc/sysconfig/iptables
在行上面有22 -j ACCEPT 下面另起一行输入跟那行差不多的,只是把22换成21,然后:wq保存。
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport <span style="color:#ff0000;">21 </span>-j ACCEPT
还要运行下,重启iptables
[root@winy ~]# service iptables restart
5 修改selinux
外网是可以访问上去了,可是发现没法返回目录(使用ftp的主动模式,被动模式还是无法访问),也上传不了,因为selinux作怪了。
修改selinux:
执行以下命令查看状态:
[root@winy ~]# getsebool -a | 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_passive_mode --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
执行上面命令,再返回的结果看到两行都是off,代表,没有开启外网的访问【下面两个命令一次执行一个,每个命令会耗一点时间等待】
[root@winy ~]# setsebool -P allow_ftpd_full_access on
[root@winy ~]# setsebool -P ftp_home_dir on
6 关闭匿名访问
修改vi /etc/vsftpd/vsftpd.conf文件:
[root@winy /]# cat /etc/vsftpd/vsftpd.conf
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
anonymous_enable变量的值默认为YES,此处改为了NO,然后保存!
重启ftp服务:
[root@winy ~]# service vsftpd restart
7 开启被动模式
默认是开启的,但是要指定一个端口范围,打开vsftpd.conf文件,在后面加上
pasv_min_port=30000
pasv_max_port=30999
表示端口范围为30000~30999,这个可以随意改。改完重启一下vsftpd
由于指定这段端口范围,iptables也要相应的开启这个范围,所以像上面那样打开iptables文件。
也是在21上下面另起一行,更那行差不多,只是把21改为30000:30999,然后:wq保存,重启下iptables。这样就搞定了。
8 设置开机启动vsftpd ftp服务
[root@winy ~]# chkconfig vsftpd on
9 Win7下测试vsftpd是否安装成功
录入用户名和密码,即可登录ftp
10 通过FTP客户端测试是否安装成功
软件名称:FileZilla
下载地址:请百度
使用方式:主机:输入ip 用户名:xxx 密码:xxx 端口 : 21
默认进入目录:/home/ftpuser


被折叠的 条评论
为什么被折叠?



