Loading... <p>一、前言</p> <p> ftp介绍:</p> <p> ftp全程是File Transfer Protocol(文件传输协议),方便于实文件交换;但是在文件传输以及账号密码发送时都是以明文传输,因此是一个明文协议</p> <p>ftp是C/S方式:</p> <p> 常见的客户端有:</p> <p> GUI方式:browers、FileZilla-client、FlashFXP、CuteFTP、GFTP</p> <p> CLI方式: lftp、wget、curl、lftpget </p> <p> 常见的服务器端:</p> <p> WU-FTPD、ProFTPD、pureftp、vsftp、Serv-U、FileZilla-server</p> <p>vsftp介绍:</p> <p> vsftp全程是Very Secure FTP(非常安全的ftp),它的最大优势就是非常安全(当然这是自己说的);是基于GPL发部的在linux或Unix上的ftp服务器软件</p> <p> 监听端口:监听在TCP的21号端口</p> <p> 连接类型:</p> <p> 命令连接:实现命令传输的连接,文件管理类命令,始终处于连接状态</p> <p> 数据连接:数据的传输,按需创建,有两种工作模式,分别是主动模式和被动模式</p> <p> 主动模式:客户端通过TCP的三层握手,与服务器端建立命令连接,命令连接建立后,服务器会主动通过tcp的20端口去连接客户端发送数据,默认去连接客户端建立命令连接端口+1端口,(如:客户端使用4001端口建立命令连接,则服务器端会主动去连接客户的4002端口,如果端口被占用,继续+1,依次类推)</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160443-77.png" title="1433927172109821.png" alt="ftp1.png" /></p> <p> 被动模式:客户端通过tcp的三次握手,与服务器端建立命令连接,命令连接建立后,服务器端通过命令连接告知客户端自己已打开数据传输端口,客户端收到信息后,通过请求服务器端告知的端口获得数据;</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160443-61.png" title="1433927864111165.png" alt="ftp2.png" /></p> <p> </p> <p> </p> <p> 数据传输格式有两种:</p> <p> 文本数据传输:ASCII</p> <p> 二进制数据:BINARY</p> <p> ftp响应码:</p> <p> 1xx: 信息类</p> <p> 2xx:成功类信息</p> <p> 3xx: 提示需要进一步补全内容类</p> <p> 4xx: 客户端错误</p> <p> 5xx:服务器端错误</p> <p> 用户认证:用户通过ftp协议访问自己的家目录中的数据,可以通过ftp便览整个文件系统,为了安全起见将用户禁锢在家目录中 </p> <p> 匿名用户认证:映射为一个系统用户ftp,为ftp用户设置权限</p> <p> OS用户:通过nsswitch服务解决用户名称解析,通过pam对系统用户进行认证(/etc/passwd,/etc/shadow)</p> <p> 虚拟用户:映射为系统某一用户,用户账号密码存储于非/etc/passwd,/etc/shadow</p> <p></p> <p> </p> <p> </p> <p>二、基于Centos6.6下的vsftp软件包介绍</p> <p> 启动脚本:/etc/rc.d/init.d/vsftpd</p> <p> 用户控制文件:/etc/vsftpd/ftpusers</p> <p> 配置文件:/etc/vsftpd/vsftpd.conf</p> <p>vsftpd配置文件介绍 :</p> <pre class="brush:bash;toolbar:false;"># 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 \\启用本地用户 # # 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 \\上传后文件的umask,也就是上传后文件的权限 # # 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 \\是否允许匿名用户上传文件,[YES | NO] # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. #anon_mkdir_write_enable=YES \\是否允许匿名用户有创建目录的权限 [YES | NO] # # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES \\是否启动消息目录 [YES | NO] # # The target log file can be vsftpd_log_file or xferlog_file. # This depends on setting xferlog_std_format parameter xferlog_enable=YES \\是否启用xferlog日志 [YES | NO] # # 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 \\是否启动上传ftp文件后,更改文件的属主 [YES | NO] #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 \\定义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 \\是否使用标准的xferlog模式 [YES | NO] # # 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 \\运行vsftpd需要非特权系统用户,默认是nobody # # 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 \\设置是否允许执行特殊的ftp命令async ABOR # # 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码上传文件 [YES | NO] #ascii_download_enable=YES \\设置是否使用ascii码下载文件 [YES | NO] # # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. \\设置定义登录ftp的欢迎语 # # 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_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 \\是否允许递归 [YES | NO] # # 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 \\设置vsftpd是否处于监听状态 # # 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 \\是否启用ipv6地址监听 guest_enable=YES \\是否启用来宾账号(默认没有) guest_username=vuser \\将来宾账号映射为那一个系统用户(默认没有) pam_service_name=vsftpd.mysql \\pam认证文件 user_config_dir=/etc/vsftpd/vuser_config\\设置匿名用户的权限配置文件位置 (默认没有) userlist_enable=YES \\此选项与下面选项userlit_deny都为YES时,/etc/vsftpd/user_list为黑名单, userlist_deny=YES \\若userlist_enable为YES,userlist_deny=NO则此文件为白名单 tcp_wrappers=YES \\支持tcp_wrappers访问限制(/etc/{hosts.allow,hosts.deny} max_clients=1024 \\限制最大并发连接数(默认没有此选项) max_per_ip=1024 \\限制每个ip同时请求的连接数(默认没有此选项) anon_max_rate=1024 \\限制匿名用户的传输速率(默认没有此选项) local_max_rate=1024 \\限制本地用户的传输速率(默认没有出选项)</pre> <p></p> <p>三、vsftpd+mysql+pam实现过程:</p> <p> 1、创建用于vsftpd的数据库,在创建表,用于存储虚拟用户账号与密码</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160443-75.png" title="1433412849801169.png" alt="F1.png" /></p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160443-25.png" title="1433412856592323.png" alt="f2.png" /></p> <p> </p> <p> 2、添加虚拟用户</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703160443-68.png" title="1433413087101336.png" alt="f3.png" /></p> <p></p> <p> 3、授权admin用户对vuser表只有查询的权限</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-18.png" title="1433413386575917.png" alt="f4.png" /></p> <p> </p> <p> 4、创建虚拟用户的映射用户</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-50.png" title="1433413567805653.png" alt="f5.png" /></p> <p> </p> <p> 5、编辑/etc/vsftpd/vsftpd.conf,添加以下信息</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-9.png" title="1433413761156343.png" alt="f6.png" /></p> <p> </p> <p> 6、在/etc/pam.d/目中中创建vsftpd.mysql,内容如下</p> <p> (1)确保安装pam_mysql之后生成了认证时所需要的共享库</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703160444-23.png" title="1433483922100106.png" alt="f9.png" /></p> <p> </p> <p> (2)在/etc/pam.d/目录中创建认证文件</p> <p><img src="//cto.wang/usr/uploads/2016/07/20160703160444-58.png" title="1433483947581925.png" alt="f8.png" /></p> <p></p> <p>7、重新启动vsftpd服务</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-83.png" title="1433484140299626.png" alt="f10.png" /> </p> <p></p> <p>8、使用虚拟用户登录ftp,验证是否可以成功登录</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-49.png" title="1433487650936619.png" alt="f11.png" /> </p> <p></p> <p> 9、为不同的虚拟用户设置不同的权限;</p> <p> (1)修改/etc/vsftpd/vsftpd.conf 文件</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-38.png" title="1433487888102731.png" alt="f12.png" /></p> <p> </p> <p> (2)默认是没有此目录的,需要手动创建</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-8.png" title="1433487953140522.png" alt="f13.png" /></p> <p> </p> <p> (3)在此目录下,分别创建以tom,obama等用户为名称的文件,内容如下</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-17.png" title="1433488275131496.png" alt="f14.png" /> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-27.png" title="1433488286594073.png" alt="f15.png" /></p> <p> </p> <p> (4)重启vsftpd服务,测试权限</p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-70.png" title="1433488964108851.png" alt="f16.png" /></p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-41.png" title="1433488977138969.png" alt="f17.png" /></p> <p> <img src="//cto.wang/usr/uploads/2016/07/20160703160444-17-1.png" title="1433488990673521.png" alt="f18.png" /></p> <p> (5)vsftpd已经实现基于mysql的认证,可以尽情使用了 </p> 最后修改:2021 年 12 月 10 日 10 : 53 AM © 允许规范转载 赞赏 如果觉得我的文章对你有用,请随意赞赏 赞赏作者 支付宝微信