ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

centos 6.4 搭建 FTP 服务器(策略管控)

2019-01-27 09:03:50  阅读:307  来源: 互联网

标签:FTP enable centos 用户 vsftpd 6.4 file YES


一、 FTP 概念

文件传输协议(File Transfer Protoco)是用于在网络上进行文件传输的一套标准协议,使用客户/服务器模式!FTP是用户普遍使用的工具!

二、FTP软件的安装(vsftpd)

1、rpm -qa | grep vsftpd  检查系统中是否安装vsftpd软件

2、yum install -y vsftpd   yum安装vsftpd

3、yum info vsftpd     查看vsftp软件信息

4、chkconfig vsftpd on  将vsftpd 设置为开机启动服务

5、chkconfig --list | grep vsftpd   确认vsftp服务是否为开机启动服务!;

三、配置FTP,配置文件保存在 :  /etc/vsftpd/vsftpd.conf

1、在配置FTP前,先将FTP配置文件进行本地备份,以便还原

首先我们在不修改任何配置文件的时候,将vsftpd服务进行启动,默认启动后支持用户宿主目录访问及匿名用户访问!FTP IP:10.67.51.39

在不知用户的情况下,可使用系统默认生成的ftp用户,或anonymous 两个系统默认用户!不需输入密码,便可直接登陆!

这样我们ftp目录 : /var/ftp 下的文件夹,即为默认目录,我们看到chen 和 pub 两个FTP目录!

     

2、匿名FTP的应用

应用:匿名FTP 往往用来提供一些公共文档,我们提供的文档,大家够可以访问的!

匿名FTP用户名: ftp   anonymous

密码:直接回车  

默认目的:ftp为用户的宿主目录 :  /var/ftp

配置/etc/vsftpd/vsftpd.conf

anonymous_enable=YES                       #配置文件默认开启匿名服务   

#anon_upload_enable=YES              #匿名访问不支持上传文件功能,此权限不给匿名用户开放

#anon_mkdir_write_enable=YES          #不允许创建目录

xferlog_enable=YES           #是否启用日志功能

#xferlog_file=/var/log/xferlog        #日志文件统一存放目录,默认不开启,需手动开启,取消#,统一方便管理!日志记录:

xferlog_std_format=YES                #日志文件记录格式 (这里为标准格式std)

#ftpd_banner=Welcome to blah FTP service.    设置登录FTP的欢迎信息,默认不开启,需手动开启,欢迎信息,自己意愿填写!这里系诶什么,登录界面显示什么!

anon_max_rate=100000

#设置匿名用户最大传输速率为100KB/s,默认无,可填写在配置文件最后,新增一行,可作为匿名用户下载限制开启

处系统默认配置,其他配置按照上面进行修改,基本实现匿名用户的登陆!

[root@zabbix ftp]# grep -v "^#" /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
ftpd_banner=Welcome to blah FTP service.
listen=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

anon_max_rate=100000

下面普及一下 常用FTP命令

(1)、ftp ftp地址  连接FTP服务器,登陆FTP

ftp>

(2)、ls - 查看目录下文件

(3)、cd - 切换目录(FTP)

(4)、bin - 二进制传输

(5)、lcd  切换下载目录(本地)

(6)、get - 下载单个文件

(7)、mget - 下载多个文件

(8)、put - 上传单个文件

(9)、mput - 上传多个文件

(10)、prompt - 关闭监护询问模式,如下载文件夹内多有文件,不用单个文件进行一一确认!

(11)、bye - 退出

(12)、open - 连接FTP服务器

(13)、user - 输入FTP服务器用户名和密码

以上命令,可进行自动化FTP脚本的运行,用来编译自动化运行脚本!

自动化进行FTP下载 : ftp -n < 脚本名称

下面简单举例,创建 ftp.auto自动化下载

1、创建脚本,并创建本地下载目录

[root@rhel ~]# vim ftp.auto
open 10.67.51.39  #连接FTP
user ftp 1    #用户名,密码
bin           #修改传输默认,二进制传输
prompt         #关闭交互模式
lcd /ftp.bak   #建立下载到本地的目录
mget  pub/*         #下载目录下的所有文件
bye                      #退出下载

mkdir /ftp.bak

我们在FTP服务器中创建几个文件,便于测试!

2、进行测试

ftp -n < ftp.auto   下载FTP中内容,也可配置任务排程,定期下载! 

四、用户访问模式

默认系统用户可以登陆,可以登陆centos 系统的用户,就可登陆FTP

我这边创建了两个用户分别为zhangsan、lisi两个用户

在/etc/passwd 中查看两个用户

 

现在我们可以通过这两个用户直接登陆FTP,是可以验证成功!默认普通用户可以登陆!看到的是自己宿主目录下的文件!

       

默认情况下支持文件的上传的下载,在windows 下直接拖拽就可!就可上传至用户的宿主目录,我们可以进入 /home/lisi 目录下查看我们上传的文件内容!

    

配置文件,开启vsftpd,FTP用户为系统用户!

如启用SElinux允许用户上传文件到宿主目录,执行如下命令,不然本地用户无法上传文件至宿主目录

setsebool -P ftp_home_dir 1

setsebool -P allow_ftpd_full_access 1

或关闭SElinux

vi /etc/selinux/config   为disable

# 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=YES                    #启用匿名访问服务,尽量关闭
#
# Uncomment this to allow local users to log in.
local_enable=YES                        #启用本地用户登录,可以登陆本地服务器的用户,即可登陆FTP服务器
#  
# Uncomment this to enable any form of FTP write command.
write_enable=YES                        #本地用户的写入权限管理
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022                        #本地用户文件权限管理
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
anon_upload_enable=YES                #开启匿名用户下载功能,默认关闭
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES           #匿名用户上传功能,默认关闭
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES                 #日志管理权限开放
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600      #用户会话空闲多久中断连接设置
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Welcome to blah FTP service.   #设置欢迎、警告标语
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_local_user=YES
#chroot_local_user=YES #chroot_list_enable=YES # (default follows) #chroot_list_file=/etc/vsftpd/chroot_list # # You may activate the "-R" option to the builtin ls. This is disabled by # default to avoid remote users being able to cause excessive I/O on large # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume # the presence of the "-R" option, so there is a strong case for enabling it. #ls_recurse_enable=YES # # When "listen" directive is enabled, vsftpd runs in standalone mode and # listens on IPv4 sockets. This directive cannot be used in conjunction # with the listen_ipv6 directive. listen=YES
listen_port=端口号 #1024以上端口,默认端口20、21,可修改服务端口! # # This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6 # sockets, you must run two copies of vsftpd with two configuration files. # Make sure, that one of the listen options is commented !! #listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES
userlist_deny=NO 
userlist_file=/etc/vsftpd.user_list 用户访问管理配置 tcp_wrappers=YES
local_max_rate=200000 #本地用户定义用户最大传输速率 anon_max_rate=100000 #限制匿名用户传输速率
max_clients=50 #服务器的总的并发连接数,同时允许多少连接存在
max_per_ip=x #每个IP同时打开几个连接

用户访问控制,限制策略

添加以下配置至配置文件,两种方式

1、限制指定的用户不能访问,而其他用户可以访问

userlist_enable=YES     开启用户访问限制功能 ,默认选项

userlist_deny=YES        拒绝指定用户访问

userlist_file=/etc/vsftpd/user_list    定义指定用户文件

2、限制指定的用户可以访问,而其他用户不可以访问

userlist_enable=YES       开启用户访问限制功能 ,默认选项

userlist_deny=NO           允许指定用户访问,开启

userlist_file=/etc/vsftpd.user_list        定义指定用户文件,格式每个用户名为一行

 

限制用户只能访问自己的宿主目录,不能进行目录切换,可对不同用户进行授权,精细化管理!

chroot_local_user=YES    只能访问 宿主目录,宿主目录变成根目录,无法切换目录

chroot_list_enable=YES         开启用户定力列表功能

chroot_list_file=/etc/vsftpd/chroot    定义不执行chroot的列表

用户有目录的 X 权限,就可以修改目录的内容,有修改目录的权限!

 

 

以上就完成FTP的配置选项!

 

 

 

 

 

 

 

 

标签:FTP,enable,centos,用户,vsftpd,6.4,file,YES
来源: https://www.cnblogs.com/Mr-henry-chen/p/10320811.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有