7

Linux系统搭建FTP服务器教程

 2 years ago
source link: https://blog.51cto.com/u_15636320/5762947
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Linux系统搭建FTP服务器教程

精选 原创

Liunx系统下有好几款很不错的ftp服务,各有特点,适应于不同的应用场合。一般在各种Linux的发行版中,默认带有的ftp软件是vsftp,本文是针对CentOs7系统下搭建vsftpd服务为例。

1.首先确定系统中已经安装了vsftpd软件,查看命令:

rpm -q vsftpd

rpm -qa |grep vsftpd

2. 安装vsftpd(以yum安装为例)

yum install -y vsftpd

3.关闭selinux和iptables(也可配置防火墙相关访问策略,反之系统阻断),设置vsftpd开机自启

永久关闭selinux

vi /etc/sysconfig/selinux

将配置SELinux=enforcing改为SELinux=disabled

保存退出并重启服务器

验证是否关闭命令:getenforce

关闭防火墙

centos 7 操作命令:systemctl stop firewalld.service

centos 6 操作命令:service stop iptables

设置vsftpd开机自启

centos 7 操作命令:systemctl enable vsftpd.service

centos 6 操作命令:chkconfig vsftpd on

4.vsftpd的配置

ftpusers 该文件用来指定哪些用户不能访问ftp服务器。

user_list 该文件用来指定的默认账户在默认情况下也不能访问ftp服务器。

vsftpd.conf vsftpd的主要配置文件,路径:

/etc/vsftpd/vsftpd.conf

vsftpd.conf的配置

是否允许匿名登录

anonymous_enable=NO

是否允许本地用户登录

local_enable=YES

是否允许本地用户对FTP服务器文件具有写权限

write_enable=YES

本地用户主目录

local_root=/var/ftp

匿名用户主目录

anon_root=/var/ftp/pub

是否允许匿名用户上传文件,如允许,须将全局的

write_enable=YES

anon_upload_enable=YES

是否允许匿名用户创建新文件夹

anon_mkdir_write_enable=YES

容许匿名用户除了新建和上传外的其他权限

anon_other_write_enable=YES

本地用户掩码

local_umask=022

设置匿名登入者新增或上传档案时的umask值

anon_umask=022

是否激活目录欢迎信息功能

dirmessage_enable=YES

xferlog_enable=YES

主动模式数据传输20端口

connect_from_port_20=NO

xferlog_std_format=YES

是否监听ipv4

listen=YES

listen_ipv6=YES

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

是否设置被动模式

pasv_enable=YES

被动模式传输使用端口

pasv_min_port=20020

pasv_max_port=20020

被动模式返回给客户端的ip地址(服务器内网穿透时使用)

pasv_address=0.0.0.0( 服务器外网ip )

设置用户访问目录,默认只允许用户自己的ftp目录

需要同时设置allow_writeable_chroot,允许受限用户的写权限,不然会报错

chroot_local_user=YES

chroot_list_enable=YES

chroot_list_file=/etc/vsftpd/chroot_list

allow_writeable_chroot=YES

5.创建例外用户文件

#哪怕没有例外用户也必须创建

vim /etc/vsftpd/chroot_list

只想让指定账户不限制在其主目录,其它账户都限制在主目录。

对于chroot_local_user与chroot_list_enable的组合效果,可以参考下表:

Linux系统搭建FTP服务器教程_linux

6. 创建ftp新用户

#新增一个test(用户名),并指定上传目录在/home/ftp/test下

useradd -g root -d /home/ftp/test -s /sbin/nologin test

如果后期想变更此用户的上传到(/XXX/ftp/test),请使用下面的命令:

usermod -d /XXX/ftp/test test

设置用户密码

passwd test

因为安全问题,vaftpd不允许匿名用户在ftp主目录上传,可以新建一个子目录,设置权限为777

7.关于local_umask和anon_umask掩码

掩码决定了上传文件的权限,掩码为022代表上传后的文件权限为

666-022=644  -> rw-r--r--

掩码即为要去除的权限为,默认设为033即可。

8. 启动vsftp服务

#centos7 操作命令

启动: systemctl start vsftpd.service

停止: systemctl stop vsftpd.service

重启: systemctl restart vsftpd.service

查看状态: systemctl status vsftpd.service

#centos6 操作命令

启动: service vsftpd start

停止: service vsftpd stop

重启: service vsftpd restart

查看状态: service vsftpd status

  • 1
  • 1收藏
  • 5评论
  • 分享
  • 举报

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK