• Centos7搭建FTP服务


    1、安装 vsftpd

    ​[root@CentOS ftp]# yum -y install vsftpd
    2、启动 vsftpd 服务

    ​[root@CentOS ~]# systemctl start vsftpd.service # 启动 vsftpd 服务
    [root@CentOS ~]# ps -ef | grep vsftpd # 查看 vsftpd 进程是否存在
    root 3753 1 0 18:51 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
    root 3758 3494 0 18:51 pts/0 00:00:00 grep --color=auto vsftpd
    [root@CentOS ~]#
    3、开放 21 端口

    ​[root@CentOS ~]# firewall-cmd --zone=public --add-port=21/tcp --permanent # 添加 21 端口
    success
    [root@CentOS ~]# firewall-cmd --reload # 重新载入
    success
    [root@CentOS ~]# firewall-cmd --zone=public --list-ports # 查看所有已开放的端口
    21/tcp 3690/tcp 3306/tcp # 可以看到 21 端口已开放
    [root@CentOS ~]#
    4、使用FileZilla进行客户端测试

    (1)首先,将传输模式设置为主动模式:

    (2)然后测试匿名登录:

    ​​使用匿名用户登录成功后,默认的主目录为 /var/ftp ,可以看到在该目录中有一个pub目录。

    ​[root@CentOS ~]# ls -l /var/ftp
    总用量 0
    drwxr-xr-x. 2 root root 6 8月 3 2017 pub # 确认pub目录已存在
    [root@CentOS ~]#
    5、配置 selinux

    默认情况下,CentOS 的FTP 是不允许实体账号登录取得用户主目录数据的,这是因为 SELinux 的问题。

    ​[root@CentOS ~]# getsebool -a | grep ftp # 查看有关 ftp 的 selinux 策略规则
    ftpd_anon_write --> off
    ftpd_connect_all_unreserved --> off
    ftpd_connect_db --> off
    ftpd_full_access --> off
    ftpd_use_cifs --> off
    ftpd_use_fusefs --> off
    ftpd_use_nfs --> off
    ftpd_use_passive_mode --> off
    httpd_can_connect_ftp --> off
    httpd_enable_ftp_server --> off
    tftp_anon_write --> off
    tftp_home_dir --> off
    [root@CentOS ~]# setsebool -P tftp_home_dir=1 # 将 tftp_home_dir 规则设置为 1
    6、建立 ftp 账户

    新建一个不能登录系统,而只能登录 ftp 服务的用户。

    ​[root@CentOS ~]# useradd ftpuser -s /sbin/nologin # 添加用户 ftpuser
    [root@CentOS ~]# passwd ftpuser # 设置密码
    7、配置 vsftpd.conf

    # 禁止匿名用户登录

    anonymous_enable=NO

    # 配置与实体用户相关的信息,可写入

    userlist_enable=YES

    userlist_deny=NO

    userlist_file=/etc/vsftpd/user_list

    之所以配置以上信息项,是因为我想只让某些人可以使用 FTP,而直接添加的用户默认不可使用 FTP 这个服务。如果我们想查看更多有关这个文件的配置说明,可以通过 man 5 vsftpd.conf 命令进行查看。

    8、将 ftpuser 用户添加到 /etc/vsftpd/user_list 文件中,编辑后的内容如下:

    ​[root@CentOS ~]# cat /etc/vsftpd/user_list
    # vsftpd userlist
    # If userlist_deny=NO, only allow users in this file
    # If userlist_deny=YES (default), never allow users in this file, and
    # do not even prompt for a password.
    # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
    # for users that are denied.
    #root
    #bin
    #daemon
    #adm
    #lp
    #sync
    #shutdown
    #halt
    #mail
    #news
    #uucp
    #operator
    #games
    #nobody
    ftpuser # 指定只有 ftpuser 用户可以使用 FTP 服务,其他用户不能使用(已注释的用户)
    [root@CentOS ~]#
    此时写入 /etc/vsftpd/user_list 的用户就是可以使用 FTP 的账号了。所以未来添加的用户如果想使用 FTP 的话,也必须要写入这个文件。

    9、重启 vsftpd 服务

    ​[root@CentOS ~]# systemctl restart vsftpd.service
    [root@CentOS ~]# ps -ef | grep vsftpd
    root 4568 1 0 19:51 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
    root 4573 3494 0 19:51 pts/0 00:00:00 grep --color=auto vsftpd
    [root@CentOS ~]#
    10、再次使用 FileZilla 进行测试

    ​​​

    如上所示,用户 ftpuser 已登录成功,默认的用户主目录为 /home/ftpuser。

    11、将 vsftpd 服务设置为开机启动

    ​[root@CentOS ~]# systemctl enable vsftpd.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
    [root@CentOS ~]#

  • 相关阅读:
    free online Twitter video downloader All In One
    Game Development Essential Terms All In One
    Offscreen Canvas All In One
    前端性能优化系列之 Service Workers 实战教程 All In One
    前端性能优化系列之 Web Workers 实战教程 All In One
    河南美食阿利茄汁面 All In One
    free online Youtube video downloader All In One
    Leetcode 2264. 字符串中最大的 3 位相同数字(可以,已解决)
    多分类任务中不同隐藏层层数对实验结果的影响(使用GPU)
    Pytorch 损失函数总结
  • 原文地址:https://www.cnblogs.com/ricksteves/p/11627683.html
Copyright © 2020-2023  润新知