[7] E20200102-1 the installation and configuration centos vsftp

First, the preparatory work

1.1, server ready

  • Operating System: centos 7.x
  • Turn off the firewall (firewall / iptables) and SELinux

    See notes "[E20200101-1] Centos 7.x turn off the firewall (firewall) and SELinux"

  • Update Server (excluding kernel)
# yum --exclude=kernel* update
  • Installation easy to use text tool (nano)
# yum -y install nano

1.2, understand the concept of "Port mode (active mode) and Pasv mode (passive mode)," the

Port mode (active mode):

When the FTP server configuration is Port Mode: The client then [C] sends a command to the server after login [S] told [server] S ( "Client C" N to open a port on the local waiting " after the server S "data connection), when [S] server receives the client information [C] will be sent to the client [C] N open ports are connected, and data services via port N.

Pasv mode (passive mode):

When the FTP server configuration is Pasv mode, then [Client C] will Login [server S] [server S] will send a message to [Client C] ( "server S" opened a on the server after the data connection port M is waiting "client C"), when [C] the client receives the server information [S] is sent, it will be connected to the server [S] M to open ports, and data services via port N.

Second, the installation vsftp

2.1, yum install vsftp

yum -y install vsftpd

2.2, start the service

systemctl start vsftpd.service

Third, the configuration vsftp

3.1, modify the configuration file

Profile Path

/etc/vsftpd

A backup configuration files

# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak 

Use nano text editor to modify the configuration file

# nano /etc/vsftpd/vsftpd.conf

Use it replaces the original configuration file

anonymous_enable=NO
write_enable=YES
chroot_local_user=YES
chroot_list_enable=YES
use_localtime=YES
local_enable=YES
allow_writeable_chroot=YES
xferlog_enable=YES
local_umask=022
pam_service_name=vsftpd
 
use_localtime=YES
listen_port=21
chroot_local_user=YES
idle_session_timeout=120
 
data_connection_timeout=120
#guest_enable=YES
#guest_username=wordpress
 
user_config_dir=/etc/vsftpd/vuser_conf
virtual_use_local_privs=YES

#pasv_enable=YES 
pasv_min_port=10060
pasv_max_port=10065
 
accept_timeout=5
connect_timeout=1

Creating the host user

//创建ftpuser用户并添加到ftp组
# useradd -g ftp -M -d /data/vsftpd -s /sbin/nologin ftpuser
//设置用户 ftpuser 的密码
# passwd ftpuser
//把 /data/vsftpd 的所有权给ftpuser账号和ftp组
# chown -R ftpuser:ftp /data/vsftpd

Create a virtual user file using a text editor nano

# nano /etc/vsftpd/vuser_passwd
# 编辑虚拟用户名单文件内容;
# 第一行账号,第二行密码;
#注意:不能使用系统保留的用户名,例如root
ftp1
12345678
ftp2
12345678

Generates virtual user data file

db_load -T -t hash -f /etc/vsftpd/vuser_passwd /etc/vsftpd/vuser_passwd.db
chmod 600 /etc/vsftpd/vuser_passwd.db

Fourth, the test vsftp

*net use /d 清除ftp连接缓存**

Annex I: vsftpd.conf Detailed profiles

########匿名用户(anonymous)设置#############
#匿名用户使用的登陆名为ftp或anonymous,口令为空;
#匿名用户不能离开匿名用户家目录,且只能下载不能上传;

#控制是否允许匿名用户登入,YES 为允许匿名登入,NO 为不允许。默认值为YES。
#anonymous_enable=YES/NO(YES)
anonymous_enable=NO

#若是启动这项功能,则使用匿名登入时,不会询问密码。默认值为NO。
#no_anon_password=YES/NO(NO)
#no_anon_password=NO

#定义匿名登入的使用者名称。默认值为ftp。
#ftp_username=ftp

##使用匿名登入时,所登入的目录。默认值为/var/ftp。
#注意ftp目录不能是777的权限属性,即匿名用户的家目录不能有777的权限。
#anon_root= /var/ftp

#如果设为YES,则允许匿名登入者有上传文件(非目录)的权限;
#只有全局的write_enable=YES(默认YES)时,此项才有效;
#当然,匿名用户必须要有对上层目录的写入权。默认值为NO;
#anon_upload_enable=YES 

#如果设为YES,则允许匿名登入者下载可阅读的档案;
#可以下载到本机阅读,不能直接在FTP服务器中打开阅读;
#anon_world_readable_only=YES/NO(YES)默认值为YES;
#anon_world_readable_only=YES

#如果设为YES,则允许匿名登入者有新增目录的权限
#只有全局的write_enable=YES(默认YES)时,此项才有效;
#当然,匿名用户必须要有对上层目录的写入权。
#anon_mkdir_write_enable=YES/NO(NO)默认值为NO。
#anon_mkdir_write_enable=NO  

#如果设为YES,则允许匿名登入者拥有上传或者建立目录之外的权限,譬如删除或者重命名。
#如果anon_upload_enable=NO,则匿名用户不能上传文件,但可以删除或者重命名已经存在的文件;
#如果anon_mkdir_write_enable=NO,则匿名用户不能上传或者新建文件夹,但可以删除或者重命名已经存在的文件夹。
#anon_other_write_enable=YES/NO(NO)默认值为NO。
#anon_other_write_enable=NO

#设置是否改变匿名用户上传文件(非目录)的属主;
#chown_uploads=YES/NO(NO)默认值为NO;
#chown_uploads=NO

#设置匿名用户上传文件(非目录)的所有者账号名称;
#建议不要设置为root;
#chown_username=username

#设置匿名登入者新增或上传档案时的 umask (匿名用户的掩码)值;
#如umask是022,这时创建一个权限为666的文件,文件的实际权限为666-022=644
#默认值为077 对应新建档案的对应权限为700;
#anon_umask=077

#若是启动这项功能,则必须提供一个档案/etc/vsftpd/banner_emails,内容为email address。
#若是使用匿名登入,则会要求输入email address,若输入的email address 在此档案内,则不允许进入。
#deny_email_enable=YES/NO(NO)默认值为NO。
#deny_email_enable=NO

#此文件用来输入email address;
#只有在deny_email_enable=YES时,才会使用到此档案。
#若是使用匿名登入,则会要求输入email address,若输入的email address 在此档案内,则不允许进入。
#banned_email_file=/etc/vsftpd/banner_emails

############本地用户设置#############
#本地用户的登录名为本地用户名,口令为此本地用户的口令;
#本地用户可以在自己家目录中进行读写操作;
#本地用户可以离开自家目录切换至有权限访问的其他目录,并在权限允许的情况下进行上传/下载。
#写在文件/etc/vsftpd/ftpusers中的本地用户禁止登陆。

#控制是否允许本地用户登入,YES 为允许本地用户登入,NO为不允许;
#local_enable=YES/NO(YES)默认值为YES;
local_enable=YES

#当本地用户登入时,将被更换到定义的目录下。默认值为各用户的家目录。
#local_root=/home/username

#设置本地用户登入者新增或上传档案时的 umask (匿名用户的掩码)值;
#如umask是022,这时创建一个权限为666的文件,文件的实际权限为666-022=644
#默认值为077 对应新建档案的对应权限为700;
local_umask=022

#本地用户上传档案后的档案权限,与chmod所使用的数值相同。默认值为0666。
#file_open_mode=0755



#############虚拟用户配置###########3
#虚拟用户使用PAM认证方式。
#设置PAM使用的名称,默认值为/etc/pam.d/vsftpd。
pam_service_name=vsftpd

#启用虚拟用户;
#guest_enable= YES/NO(NO)默认值为NO。
#guest_enable=YES

#这里用来映射虚拟用户。默认值为ftp。
#guest_username=wordpress

#当该参数激活(YES)时,虚拟用户使用与本地用户相同的权限;
#当此参数关闭(NO)时,虚拟用户使用与匿名用户相同的权限。
#virtual_use_local_privs=YES/NO(NO)默认情况下此参数是关闭的(NO)。
virtual_use_local_privs=YES




use_localtime=YES
listen_port=21
chroot_local_user=YES
idle_session_timeout=120
 
data_connection_timeout=120





#设置虚拟用户账户文件的主目录文件夹地址
user_config_dir=/etc/vsftpd/vuser_conf



#pasv_enable=YES 
pasv_min_port=10060
pasv_max_port=10065
 
accept_timeout=5
connect_timeout=1


#是否允许登陆用户有写权限。属于全局设置,默认值为YES;
#write_enable=YES/NO(YES)默认值为YES;
write_enable=YES

#是否将所有用户限制在主目录,YES为启用 NO禁用;
#在安装vsftpd后不做配置的话,ftp用户是可以向上切换到要目录之外的;
#chroot_local_user=YES/NO (NO) 默认值为NO;
chroot_local_user=YES

##用于指定用户列表文件中的用户不允许切换到上级目录;
#chroot_list_enable=YES/NO (NO) 默认值为NO;
chroot_list_enable=YES

#是否限制在“主目录”下的用户名单文件地址;
#当chroot_list_enable=YES(默认值为NO)时生效;
#至于是“限制名单”还是“排除名单”,这取决于chroot_local_user的值;
#当chroot_local_user=YES时,该文件里的用户作为“例外”不做限制;
#当chroot_local_user=NO时,该文件里的用户作为“例外”受到限制;
chroot_list_file=/etc/vsftpd/chroot_list



use_localtime=YES
allow_writeable_chroot=YES
xferlog_enable=YES

Guess you like

Origin www.cnblogs.com/eword/p/E20200102-1.html