• VsFtpd的环境搭建,虚拟登录,Linux服务器


    一、背景和环境监察

            由于单位有需求,需要对数据在边界上进行数据传输,但是边界不支持FTP服务,如果添加一个Linux实际账号,还可能存在账号安全问题。

    第一步:判断服务器是否安装VSFTP
    命令:rpm -qa | grep vsftp

    卸载当前软件,并且重新安装,避免版本不是新的
    Yum remove vsftpd-3.0.2-25.el7.x86_64
    删除相关历史文件:rm –rf /上一步查询出相对于的文件目录。
    rm –rf 慎用

    安装VsFTP 
    yum install vsftpd

     yum remove vsftpd-3.0.2-25.el7.x86_64 直接卸载当前服务。

    1. 再次安装
    2. yum install vsftpd
    3. 一、虚拟用户,所有虚拟用户会统一映射为一个指定的系统帐号,访问共享位置,即为此系统帐号的家目录,各虚拟用户可被
    4. 赋予不同的访问权限,通过匿名用户的权限控制参数进行指定。
    5. 需求:建立2个ftp账号, yisa,可读可写 只读。共享使用vsftpduser虚系统账号进行访问.
    6. ##安装
    7. yum install -y vsftpd
    8. ##设置开机启动
    9. systemctl enable vsftpd.service
    10. ##启动
    11. systemctl start vsftpd.service
    12. ##停止
    13. systemctl stop vsftpd.service
    14. ##查看状态
    15. systemctl status vsftpd.service

    二、直接配置文件追加(覆盖之前的文件)
    2.配置/etc/vsftpd/vsftpd.conf

    1. cat > /etc/vsftpd/vsftpd.conf << EOF
    2. # Example config file /etc/vsftpd/vsftpd.conf
    3. #
    4. # The default compiled in settings are fairly paranoid. This sample file
    5. # loosens things up a bit, to make the ftp daemon more usable.
    6. # Please see vsftpd.conf.5 for all compiled in defaults.
    7. #
    8. # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
    9. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
    10. # capabilities.
    11. #
    12. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
    13. anonymous_enable=NO
    14. #
    15. # Uncomment this to allow local users to log in.
    16. # When SELinux is enforcing check for SE bool ftp_home_dir
    17. local_enable=YES
    18. #
    19. # Uncomment this to enable any form of FTP write command.
    20. write_enable=YES
    21. #
    22. # Default umask for local users is 077. You may wish to change this to 022,
    23. # if your users expect that (022 is used by most other ftpd's)
    24. local_umask=022
    25. #
    26. # Uncomment this to allow the anonymous FTP user to upload files. This only
    27. # has an effect if the above global write enable is activated. Also, you will
    28. # obviously need to create a directory writable by the FTP user.
    29. # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
    30. #anon_upload_enable=YES
    31. #
    32. # Uncomment this if you want the anonymous FTP user to be able to create
    33. # new directories.
    34. anon_mkdir_write_enable=NO
    35. #
    36. # Activate directory messages - messages given to remote users when they
    37. # go into a certain directory.
    38. dirmessage_enable=YES
    39. #
    40. # Activate logging of uploads/downloads.
    41. xferlog_enable=YES
    42. #
    43. # Make sure PORT transfer connections originate from port 20 (ftp-data).
    44. connect_from_port_20=YES
    45. #
    46. # If you want, you can arrange for uploaded anonymous files to be owned by
    47. # a different user. Note! Using "root" for uploaded files is not
    48. # recommended!
    49. chown_uploads=YES
    50. #chown_username=whoever
    51. #
    52. # You may override where the log file goes if you like. The default is shown
    53. # below.
    54. #xferlog_file=/var/log/xferlog
    55. #
    56. # If you want, you can have your log file in standard ftpd xferlog format.
    57. # Note that the default log file location is /var/log/xferlog in this case.
    58. xferlog_std_format=YES
    59. #
    60. # You may change the default value for timing out an idle session.
    61. #idle_session_timeout=600
    62. #
    63. # You may change the default value for timing out a data connection.
    64. #data_connection_timeout=120
    65. #
    66. # It is recommended that you define on your system a unique user which the
    67. # ftp server can use as a totally isolated and unprivileged user.
    68. #nopriv_user=ftpsecure
    69. #
    70. # Enable this and the server will recognise asynchronous ABOR requests. Not
    71. # recommended for security (the code is non-trivial). Not enabling it,
    72. # however, may confuse older FTP clients.
    73. async_abor_enable=YES
    74. #
    75. # By default the server will pretend to allow ASCII mode but in fact ignore
    76. # the request. Turn on the below options to have the server actually do ASCII
    77. # mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains
    78. # the behaviour when these options are disabled.
    79. # Beware that on some FTP servers, ASCII support allows a denial of service
    80. # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
    81. # predicted this attack and has always been safe, reporting the size of the
    82. # raw file.
    83. # ASCII mangling is a horrible feature of the protocol.
    84. ascii_upload_enable=YES
    85. ascii_download_enable=YES
    86. #
    87. # You may fully customise the login banner string:
    88. ftpd_banner=Welcome to blah FTP service.
    89. #
    90. # You may specify a file of disallowed anonymous e-mail addresses. Apparently
    91. # useful for combatting certain DoS attacks.
    92. #deny_email_enable=YES
    93. # (default follows)
    94. #banned_email_file=/etc/vsftpd/banned_emails
    95. #
    96. # You may specify an explicit list of local users to chroot() to their home
    97. # directory. If chroot_local_user is YES, then this list becomes a list of
    98. # users to NOT chroot().
    99. # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
    100. # the user does not have write access to the top level directory within the
    101. # chroot)
    102. chroot_local_user=YES
    103. #chroot_list_enable=YES
    104. # (default follows)
    105. #chroot_list_file=/etc/vsftpd/chroot_list
    106. #
    107. # You may activate the "-R" option to the builtin ls. This is disabled by
    108. # default to avoid remote users being able to cause excessive I/O on large
    109. # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
    110. # the presence of the "-R" option, so there is a strong case for enabling it.
    111. #ls_recurse_enable=YES
    112. #
    113. # When "listen" directive is enabled, vsftpd runs in standalone mode and
    114. # listens on IPv4 sockets. This directive cannot be used in conjunction
    115. # with the listen_ipv6 directive.
    116. listen=NO
    117. #
    118. # This directive enables listening on IPv6 sockets. By default, listening
    119. # on the IPv6 "any" address (::) will accept connections from both IPv6
    120. # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
    121. # sockets. If you want that (perhaps because you want to listen on specific
    122. # addresses) then you must run two copies of vsftpd with two configuration
    123. # files.
    124. # Make sure, that one of the listen options is commented !!
    125. listen_ipv6=YES
    126. pam_service_name=vsftpd
    127. userlist_enable=YES
    128. tcp_wrappers=YES
    129. use_localtime=YES
    130. #服务监听端口 FTP服务
    131. listen_port=10000
    132. idle_session_timeout=300
    133. guest_enable=YES
    134. guest_username=vsftpduser
    135. user_config_dir=/etc/vsftpd/vconf
    136. data_connection_timeout=600
    137. virtual_use_local_privs=YES
    138. pasv_min_port=40000
    139. pasv_max_port=40010
    140. accept_timeout=5
    141. connect_timeout=10
    142. allow_writeable_chroot=YES
    143. max_clients=3000
    144. max_per_ip=3000
    145. EOF

    3、建立FTP用户账号

    1. cat >> /etc/vsftpd/virtusers << EOF
    2. yisa
    3. yisa123456
    4. EOF

     4、生成用户数据文件

    1. db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db
    2. #设定PAM验证文件,并指定对虚拟用户数据库文件进行读取
    3. chmod 600 /etc/vsftpd/virtusers.db 

     5、修改 /etc/pam.d/vsftpd 文件

    1. ## 修改前先备份
    2. cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
    3. cat > /etc/pam.d/vsftpd << EOF
    4. #%PAM-1.0
    5. auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers
    6. account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers
    7. EOF

    6.新建系统用户vsftpduser,用户目录为/home/vsftpduser(可选) 

    1. 此步骤可选,可以直接使用常规的可以登陆的ssh用户,这里为了独立使用,才创建了专用的不可登陆用户vsftpduser来负责ftp的操作。如果直接使用普通的ssh登陆用户,则后续步骤中的vsftpduser改成相应的ssh用户即可。
    2. #用户登录终端设为/bin/false(即:使之不能登录系统)
    3. useradd vsftpduser -d /home/vsftpduser -s /bin/false
    4. chown -R vsftpduser:vsftpduser /home/vsftpduser

    7.建立Ftp用户个人配置文件

    1. 让ftpusertest1与ftpusertest2都配置成同样的local_root,表示共享同样的数据目录,然后分别设置write_enable权限为读写及只读,具体如下:
    2. mkdir /etc/vsftpd/vconf
    3. cd /etc/vsftpd/vconf
    4. #建立用户yisa配置文件,其中的write_enable=YES表示可以读写
    5. cat > /etc/vsftpd/vconf/yisa << EOF
    6. local_root=/home/vsftpduser/ftpdatadir/
    7. write_enable=YES
    8. EOF
    9. #建立用户yisa02配置文件,其中的write_enable=NO表示只可以读
    10. cat > /etc/vsftpd/vconf/yisa02<< EOF
    11. local_root=/home/vsftpduser/ftpdatadir/
    12. write_enable=NO
    13. EOF
    14. #建立ftpdatadir根目录
    15. mkdir -p /home/vsftpduser/ftpdatadir/
    16. chown -R vsftpduser:vsftpduser /home/vsftpduser/ftpdatadir/

     8.重启测试

    systemctl restart vsftpd.service

     匿名用户登陆测试,可以发现匿名ftp登陆失败,符合预期结果,因为在/etc/vsftpd/vsftpd.conf中配置了全局的anonymous_enable=NO,表明不允许匿名访问anonymous_enable=NO 

     搭建成功,上述为FTP,所以在使用FTP时候切记使用非加密协议,FTP协议登录,否则无法登录。

  • 相关阅读:
    全网最全系统MySQL5.7.17安装教程配置(配详细的图文解释)
    创建对象在堆区如何分配内存
    学习open62541 ---[68] 使用Wireshark观察通信消息
    ModStart 中HasAdminQuickCRUD 的功能使用解析
    【Unity3D】UI Toolkit数据动态绑定
    考研数据结构填空题整合
    [ICS] Inferno(地狱) ETH/IP未授权访问,远程控制工控设备利用工具
    python安全工具开发笔记(二)——python Web编程
    NAT技术
    力扣记录:Hot100(1)——1-19
  • 原文地址:https://blog.csdn.net/weixin_38822045/article/details/125564893