设为首页 收藏本站
查看: 864|回复: 0

[经验分享] Vsftpd在centos6.4的尝试

[复制链接]

尚未签到

发表于 2018-4-28 13:50:47 | 显示全部楼层 |阅读模式
  1 安装软件
  可以去官网下载,我直接yum安装了,版本为vsftpd.x86_64 0:2.2.2-14.el6   ,我的测试都比较简单,大家可以照着做一下。
  2文件服务器的三种登录方式
  ①匿名登录
  vsftpd.conf默认是开启匿名登录的,不信你看
  # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  anonymous_enable=YES
  如果没开启请把注释取消
  

  默认情况下,匿名的家目录在/var/ftp/pub目录下
  在windows宿主测试,发现如何都是未连接,后来发现时iptables on了
  最终可以登录,也可以下载
DSC0000.jpg

  在图形界面也是ok的
  不过你可能想到,不能上传文件,原因是未开启权限
DSC0001.jpg

  解决办法是在vsftpd.conf添加几行,顺便咱们修改下家目录
  #ano's directory
  anon_root=/var/liuliancao
  把如下功能打开,也可以自己写哈
  anon_upload_enable=YES
  anon_mkdir_write_enable=YES
  

  可以上传
DSC0002.jpg

  可以创建文件夹
DSC0003.jpg

  删除就不行,当然也用不到,毕竟不是一个安全的配置。
  ②使用本地用户登录
  此时就建议禁用anonymous了,一般公司肯定不会开启anonymous
  所以在vsftpd.conf的anonymous_enable=YES改为NO,此时即关闭了匿名
DSC0004.jpg

  默认情况下是允许所有本地用户登录,当要分别考虑授权的时候,就得启动ftp_users(你可以看看里面的内容)文件
  默认情况:
  使用本地用户可以在外网登录,root除外,这个通常是由列表确定
  默认情况下,
  在配置文件的结尾有这行
  userlist_enable=YES    #使用userlist,且userlist上的全部不给登录
  userlist_deny=YES       #在使用userlist情况下,列表中的用户被拒绝
  如果
  userlist_deny=NO
  则userlist指定的是允许的用户,当然如果你不想考虑这些,那么就把你讨厌的人拉入ftpusers这个黑名单吧
  我建议使用userlist_enable=YES  userlist_deny=NO组合,这样,ftpusers放黑名单,userlist放白名单,这样更安全点
  当我在ftpusers放置liuliancao时,对于liuliancao和lqx两个用户
DSC0005.jpg

DSC0006.jpg

  而此时进入的是用户的家目录,由于刚建的用户没有文件,所以这样,不信可以试下,但是此时用户可以cd到根,显然不符合安全性,所以这里建议要设置chroot,把用户绑定在其家目录下
  所以修改如下几行,先别改,咱们分析下
  chroot_local_user=YES
  这里的YES指的是什么呢?
  首先是启用一个特殊的列表,其次是默认所有用户都限制在家目录中,但列表时特殊名单,不被限制
  如果是NO呢
  也启用那个特殊的列表,但是默认所有用户不限制在家目录中,
  

  那思考下,此时我有两个用户,一个liuliancao,一个lqx,我把chroot_local_user设为NO,那个特殊的列表中有liuliancao,没有lqx,此时谁会被限制在家目录中?
  肯定是黑名单liuliancao会被限制,^_^
  测试下,我修改了下这几行文件
  chroot_local_user=NO
  chroot_list_enable=YES
  # (default follows)
  chroot_list_file=/etc/vsftpd/chroot_list
  

  在chroot_list增加了liuliancao
  

  结果为:
DSC0007.jpg

DSC0008.jpg

  一般情况肯定设置chroot为YES哦,毕竟为了安全着想啊
  另外可以通过增加一条
  local_root=/var/liuliancao来指定本地用户连接ftp的默认家目录
  

  ③虚拟用户设置 参考http://bbs.51cto.com/thread-557955-1.html
  第一步,创建txt列表,记录虚拟用户
  Tec为普通用户,可以下载
  Ball为vip 可以下载,上传,创建目录
  # cat /etc/vsftpd/vuser.txt   #奇数行用户名,偶数行密码哦
  Tec
  Tec
  Ball
  Ball
  

  第二步,使用db_load命令生成db数据库(我的centos6.4最小安装没有,没有请yum -y install db4)
  

  这个命令想来也挺好记
  db_load -T  -t hash -f /etc/vsftpd/vuser.txt /etc/vsftpd/vuser.db
  -T:让程序把非数据库的文本转换为数据库db型
  -t hash:转换为hash数据库
  -f file:txt文件位置,即源文件
  最后参数:目标文件
  

  然后记得修改下数据库的权限
  # chmod 600 /etc/vsftpd/vuser.db   #bash中,最后一个参数可以使用esc+.(centos支持)或者alt+.调出来,很方便
  

  顺便添加以下系统用户,即虚拟用户对应的系统用户,Tec是普通ftp用户,只允许下载,Ball允许上传下载
  

  第三步,为vsftpd添加pam认证,64位和32位肯定不一样,db不用加db
  # cat /etc/pam.d/vsftpd
  #%PAM-1.0
  #session    optional     pam_keyinit.so    force revoke
  #auth       requiredpam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
  #auth       requiredpam_shells.so
  #auth       includepassword-auth
  #account    includepassword-auth
  #session    required     pam_loginuid.so
  #session    includepassword-auth
  auth     required    /lib64/security/pam_userdb.so     db=/etc/vsftpd/vuser       #64位是这样,vuser不用写db
  account        required    /lib64/security/pam_userdb.so  db=/etc/vsftpd/vuser
  

  第四步,为用户设置家目录,提供权限访问,这里的用户可以不同名,我只是为了方便点,所以建议同名
  # useradd -d /var/ftp/Tec/   Tec
  # useradd -d /var/ftp/Ball/   Ball
  # chmod 500 /var/ftp/Tec
  # chmod 700 /var/ftp/Ball
  

  第五步,修改主配置文件
  pam_service_name=vsftpd
  user_config_dir=/etc/vsftpd/vuserconfig   #自己等会创建的配置文件目录
  max_clients=300
  max_per_ip=10;
  userlist_enable=YES
  tcp_wrappers=YES
  

  第六步,修改用户配置文件
  

  对于普通用户Tec有:
  # cat  /etc/vsftpd/vuserconfig/Tec
  guest_enable=YES            #允许虚拟用户登录
  write_enable=NO            #不准写入,即上传等写操作
  gues_username=Tec     #指定guest用户名
  anon_world_readable_only=no #这里指定
  anon_max_rate=50000   指定最大下载速率#
  

  对于特权用户Ball来说:
  

  # cat /etc/vsftpd/vuserconfig/Ball
  guest_enable=YES
  guest_username=Ball
  write_enable=YES
  anon_mkdir_write_enable=YES
  anon_upload_enable=YES
  anon_world_readable_only=NO
  anon_max_rate=100000
  

  登录发现报错
  在网上看到这篇博文,挺好的,http://www.it165.net/admin/html/201305/1296.html,当然我建议你要检查你的user_list究竟是允许还是不允许用户登录,最好的办法就是控制变量
DSC0009.jpg

  结果我重新生成了以下就行了,然后接着报错
DSC00010.jpg

  看来我输错了
  

  修改下配置文件
  就好了
DSC00011.jpg

  但是不可以dir
DSC00012.jpg

  发现我的Tec家目录居然是root创建的,所以修改家目录属主就好了
  # chown Tec:Tec /var/ftp/Tec
DSC00013.jpg

  下面测试下功能是否完整
  Tec:
  可以下载
DSC00014.jpg

  不可以上传和创建目录
DSC00015.jpg

DSC00016.jpg

  对于Ball:
  可上传,下载,创建目录
  此时我的配置文件为下面的,仅供参考
  # Make sure PORT transfer connectionsoriginate from port 20 (ftp-data).
  connect_from_port_20=YES
  #
  # If you want, you can arrange for uploadedanonymous 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 whenxferlog_enable=YES and xferlog_std_format=YES
  # WARNING - changing this filename affects/etc/logrotate.d/vsftpd.log
  xferlog_file=/var/log/vsftpd.log
  #
  # Switches between logging into vsftpd_log_fileand xferlog_file files.
  # NO writes to vsftpd_log_file, YES toxferlog_file
  xferlog_std_format=YES
  #
  # You may change the default value fortiming out an idle session.
  #idle_session_timeout=600
  #
  # You may change the default value fortiming out a data connection.
  #data_connection_timeout=120
  #
  # It is recommended that you define on yoursystem a unique user which the
  # ftp server can use as a totally isolatedand unprivileged user.
  #nopriv_user=ftpsecure
  #
  # Enable this and the server will recogniseasynchronous ABOR requests. Not
  # recommended for security (the code isnon-trivial). Not enabling it,
  # however, may confuse older FTP clients.
  #async_abor_enable=YES
  #
  # By default the server will pretend toallow ASCII mode but in fact ignore
  # the request. Turn on the below options tohave the server actually do ASCII
  # mangling on files when in ASCII mode.
  # Beware that on some FTP servers, ASCIIsupport allows a denial of service
  # attack (DoS) via the command "SIZE/big/file" in ASCII mode. vsftpd
  # predicted this attack and has always beensafe, reporting the size of the
  # raw file.
  # ASCII mangling is a horrible feature ofthe protocol.
  #ascii_upload_enable=YES
  #ascii_download_enable=YES
  #
  # You may fully customise the login bannerstring:
  #ftpd_banner=Welcome to blah FTP service.
  #
  # You may specify a file of disallowedanonymous e-mail addresses. Apparently
  # useful for combatting certain DoSattacks.
  #deny_email_enable=YES
  # (default follows)
  #banned_email_file=/etc/vsftpd/banned_emails
  #
  # You may specify an explicit list of localusers 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=NO
  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 ableto cause excessive I/O on large
  # sites. However, some broken FTP clientssuch 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 isenabled, vsftpd runs in standalone mode and
  # listens on IPv4 sockets. This directivecannot be used in conjunction
  # with the listen_ipv6 directive.
  listen=YES
  #
  # This directive enables listening on IPv6sockets. To listen on IPv4 and IPv6
  # sockets, you must run two copies ofvsftpd with two configuration files.
  # Make sure, that one of the listen optionsis commented !!
  #listen_ipv6=YES
  pam_service_name=vsftpd
  user_config_dir=/etc/vsftpd/vuserconfig
  max_clients=300
  max_per_ip=10
  userlist_enable=YES
  userlist_deny=NO
  tcp_wrappers=YES
  由于db的操作比较简单,如果用户多可以使用脚本,所以我觉得mysql可能就没必要了。
  最后还发现一个问题:
  资源管理器默认不会提示登录,反而会提示无法访问,最后通过
  考虑原因可能是默认不允许匿名登录,所以只要在输入ftp://Tec@108.108.108.31即可,即添加好用户名的方式,最终可以登录
  

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-453225-1-1.html 上篇帖子: CentOS 6.5 安装 Nginx 1.7.8 教程 下篇帖子: centos7没有安装ifconfig的解决办法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表