vsftpd
# FTP的安装
# 安装
# yum install -y vsftpd
# 设置开机启动
# systemctl enable vsftpd.service
# 启动
# systemctl start vsftpd.service
# 停止
# systemctl stop vsftpd.service
# 查看状态
# systemctl status vsftpd.service
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
# 配置FTP
# 打开配置文件
# vim /etc/vsftpd/vsftpd.conf
# 显示行号
:set nu
# 修改配置 12 行
anonymous_enable=NO
# 修改配置 33 行
anon_mkdir_write_enable=YES
# 修改配置48行
chown_uploads=YES
# 修改配置72行
async_abor_enable=YES
# 修改配置83行
ascii_upload_enable=YES
# 修改配置84行
ascii_download_enable=YES
# 修改配置87行
ftpd_banner=Welcome to blah FTP service.
# 修改配置101行
chroot_local_user=YES
# 修改配置115行
listen=YES
# 修改配置124行
listen_ipv6=NO
# 添加下列内容到vsftpd.conf末尾
use_localtime=YES
listen_port=21
idle_session_timeout=300
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd/vconf
data_connection_timeout=1
virtual_use_local_privs=YES
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=41000
accept_timeout=5
connect_timeout=1
allow_writeable_chroot=YES
xferlog_std_format=YES
dual_log_enable=YES
vsftpd_log_file=/var/log/vsftpd.log
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
52
53
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
52
53
# 建立宿主用户
新建用户vsftpd
,用户目录为/upload
,用户登录终端设为/bin/false
(即:使之不能登录系统)
# mkdir -p /upload
# useradd vsftpd -d /upload -s /bin/false
# chown -R vsftpd:vsftpd /upload
1
2
3
4
5
2
3
4
5
# 虚拟用户配置
# 本地文件生成虚拟用户
# 建立用户文件
# 创建编辑用户文件
# vim /etc/vsftpd/virtusers
public
123.com
1
2
3
4
2
3
4
- 第一行为用户名,第二行为密码。不能使用root作为用户名
# 生成用户数据文件
# db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db
# chmod 600 /etc/vsftpd/virtusers.db
1
2
2
# 修改 /etc/pam.d/vsftpd 文件
设定PAM验证文件,并指定对虚拟用户数据库文件进行读取
# 修改前先备份
# cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
# vim /etc/pam.d/vsftpd
# 先将配置文件中原有的 auth 及 account 的所有配置行均注释掉
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers
1
2
3
4
5
6
7
2
3
4
5
6
7
- 如果系统为32位,上面改为lib
# 建立虚拟用户个人配置文件
- 建立虚拟用户public配置文件
# mkdir /etc/vsftpd/vconf
# cd /etc/vsftpd/vconf
# touch public
1
2
3
4
5
2
3
4
5
- 编辑public用户配置文件,内容如下,其他用户类似
# vim public
local_root=/upload
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
2
3
4
5
6
7
# 获取AD域控用户
# 启用pam
# 执行图形命令
# setup
1
2
2
- 没有命令的话,安装:yum -y install setuptool
- 没有authentication configuration选项: 安装authconfig
- 确定一点有没有安装nslcd,没有安装的话,安装nss-pam-ldapd
# 配置nslcd
修改/etc/nslcd.conf
配置文件
# vim /etc/nslcd.conf
# 打开文件110行-117行的注释
#修改文件最后面如下内容。
uri ldap://10.193.200.4/
base ou=User,ou=Veoneer,dc=cn04-corp,dc=int
binddn cn=vsftp,ou=vsftpAuthen, dc=cn04-corp,dc=int
bindpw xxxxxx
ssl off
tls_reqcert never
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
重启nslcd
# systemctl restart nslcd
1
# 修改 /etc/pam.d/vsftpd 文件
# 修改前先备份
# cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
# vim /etc/pam.d/vsftpd
#先将配置文件中原有的 auth 及 account 的所有配置行均注释掉
auth required pam_ldap.so
account required pam_ldap.so
1
2
3
4
5
6
7
2
3
4
5
6
7
# 配置windows AD域控用户
在域控中修改用户属性,选择Attribute Editor
配置下面4个地方
uidNumber
gidNumber
loginShell /sbin/nologin
unixHomeDirectory /upload
1
2
3
4
2
3
4
# 建立虚拟用户个人配置文件
# 查看是否从域控获取到用户
# getent passwd
# mkdir /etc/vsftpd/vconf
# cd /etc/vsftpd/vconf
# 这里建立域控中用户public的配置文件
# touch public
# 编辑public用户配置文件,内容如下,其他用户类似
# vim public
local_root=/upload
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
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 防火墙设置
防火墙开启TCP21
端口和TCP40000-41000
端口
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
1
2
3
4
2
3
4
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
2
3
# 问题
# 500、503 、200等问题
- 关闭SELINUX
# 查看SELINUX是否禁用
# getenforce
# 临时禁用
# setenforce 0
# 永久禁用
#打开SELINUX配置文件
# vim /etc/selinux/config
#修改配置参数
#注释
SELINUX=enforcing
#增加
SELINUX=disabled
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 临时和永久都要执行,就用重启了
# 其他
给虚拟用户配置文件加权限
# chmod -R 775 /home/vsftpd/public
1
Last Updated: 2021/07/12, 17:34:59