ftp服务器
# vsftpd安装
# 停止防火墙
firewall-cmd --state
systemctl stop firewalld.service
# 关闭防火墙
systemctl disable firewalld.service
sestatus #查询是否开启了selinux
setenforce 0 #临时关闭selinux
rpm -qa |grep ftp
yum remove vsftpd -y
yum remove ftp -y
yum install db4 db4-utils vsftpd
# 开机自启动
systemctl enable vsftpd
# 启动vsftpd
systemctl start vsftpd
# 重启vsftpd
systemctl restart vsftpd
# 停止vsftpd
systemctl stop vsftpd
# 关闭vsftpd
systemctl disable vsftpd
# 查看vsftpd状态
systemctl status vsftpd.service
#列出与ftp相关的设置
getsebool -a|grep ftp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 配置FTP
# 1、修改配置文件
#打开配置文件
vim /etc/vsftpd/vsftpd.conf
#显示行号
:set number
#修改配置 12 行 设定不允许匿名访问
anonymous_enable=NO
#修改配置 33 行
anon_mkdir_write_enable=YES
#修改配置48行
chown_uploads=YES
#修改配置72行
async_abor_enable=YES
#修改配置83行 设定支持ASCII模式的上传和下载功能
ascii_upload_enable=YES
#修改配置84行
ascii_download_enable=YES
#修改配置86行 定义ftp连接欢迎语句
ftpd_banner=Welcome to blah FTP service.
#修改配置101行 使用户不能离开主目录, 启用例外用户名单,指定例外用户列表文件,列表中用户不被锁定在主目录
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
#添加下列内容到vsftpd.conf末尾
use_localtime=YES
listen_port=21
idle_session_timeout=300
data_connection_timeout=1
virtual_use_local_privs=YES
#配置PASV模式vsftpd默认没有开启PASV模式,设置被动模式下,建立数据传输可使用的端口范围的最大值
allow_writeable_chroot=YES
guest_enable=YES
guest_username=www
user_config_dir=/etc/vsftpd/vuser_conf
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=40010
#关闭被动模式下的IP安全检查
pasv_promiscuous=YES
accept_timeout=5
connect_timeout=1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
根据配置文件,
- 建立目录
/etc/vsftpd/vuser_conf
,用于存放虚拟用户个人配置 - 没有例外用户时,也必须创建
chroot_list
文件,内容可为空。
参考:vsftpd配置文件详解 (opens new window)
# 2、建立用户文件
创建虚拟用户临时文件/etc/vsftpd/vuser_passwd.txt
,新建虚拟用户和密码,其中shollin、gmzx为虚拟用户名,123456为密码,如果有多个用户,依次格式填写即可:
shollin
841220
gmzx
Gm.ftp.6139
1
2
3
4
2
3
4
# 3、生成用户数据文件
生成Vsftpd虚拟用户数据库认证文件,设置权限:
db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db
#设定PAM验证文件,并指定对虚拟用户数据库文件进行读取
chmod 700 /etc/vsftpd/vuser_passwd.db
1
2
3
4
2
3
4
# 4、修改 /etc/pam.d/vsftpd 文件
配置PAM认证文件,/etc/pam.d/vsftpd行首加入如下两行,其余行注释掉:
# 修改前先备份
cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
vi /etc/pam.d/vsftpd
#先将配置文件中原有的 auth 及 account 的所有配置行均注释掉
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vuser_passwd
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vuser_passwd
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd
account required pam_userdb.so db=/etc/vsftpd/vuser_passwd
1
2
2
# 6、新建系统用户gmzx,用户目录为/mnt/www
#用户登录终端设为/bin/false(即:使之不能登录系统)
useradd www -d /home/vsftpd -s /bin/false
chown -R www:www /mnt/www
1
2
3
2
3
# 7、建立虚拟用户个人配置文件
mkdir /etc/vsftpd/vuser_conf
cd /etc/vsftpd/vuser_conf
#这里建立虚拟用户leo配置文件
touch shollin
#编辑leo用户配置文件,内容如下,其他用户类似
vi shollin
local_root=/mnt/www
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 8、放行端口
IPtables 的设置方式:
vi /etc/sysconfig/iptables
#编辑iptables文件,添加如下内容,开启21端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 40000:40010 -j ACCEPT
firewall 的设置方式:
firewall-cmd --zone=public --add-service=ftp --permanent
firewall-cmd --zone=public --add-port=21/tcp --permanent
firewall-cmd --zone=public --add-port=40000-40010/tcp --permanent
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
云服务器安全组放行
# ftp客户端
filezilla、xftp
FTP模式与数据端口 FTP 分为两类,PORT FTP和PASV FTP,PORT FTP是一般形式的FTP。这两种FTP在建立控制连接时操作是一样的,都是由客户端首先和FTP服务器的控制端口(默认值为21)建立控制链接,并通过此链接进行传输操作指令。它们的区别在于使用数据传输端口(ftp- data)的方式。PORT FTP由FTP服务器指定数据传输所使用的端口,默认值为20。PASV FTP由FTP客户端决定数据传输的端口。 PASV FTP这种做法,主要是考虑到存在防火墙的环境下,由客户端与服务器进行沟通(客户端向服务器发出数据传输请求中包含了数据传输端口),决定两者之间的数据传输端口更为方便一些
设置被动访问模式或自动
# 常见问题
多看客户商的访问日志,从中查找问题,大多与权限、防火墙相关。
1、425 Security: Bad IP connecting.