创建FTP服务器
1、安装FTP服务

yum install -y vsftpd

默认的FTP服务的配置文件路径为/etc/vsftpd

cd /etc/vsftpd
[root@test924 vsftpd]# ll
total 20
-rw------- 1 root root 125 Apr 1 12:55 ftpusers
-rw------- 1 root root 361 Apr 1 12:55 user_list
-rw------- 1 root root 5116 Apr 1 12:55 vsftpd.conf
-rwxr--r-- 1 root root 338 Apr 1 12:55 vsftpd_conf_migrate.sh
解析:
vsftpd.conf FTP核心配置文件
ftpusers 黑名单文件,此文件里的用户不允许访问 FTP 服务器。
user_list 白名单文件,是允许访问 FTP 服务器的用户列表。
vsftpd_conf_migrate.sh 是vsftpd操作的一些变量和设置
另:使用命令 rpm -ql vsftpd 可列出vsftpd中包含的文件

2、设置开机启动项
[root@test924 ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

3、启动FTP服务
[root@test924 ~]# systemctl start vsftpd

查看FTP服务网络状态
[root@test924 ~]# netstat -antup | grep ftp
tcp6 0 0 :::21 :::* LISTEN 3907/vsftpd

4、设置FTP配置文件
先将配置文件备份,创建一个去掉注释和空行的核心配置文件
[root@test924 vsftpd]# mv vsftpd.conf vsftpd.conf_bak
[root@test924 vsftpd]# grep -v "#" vsftpd.conf_bak | grep -v "^$" > vsftpd.conf
[root@test924 vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd.conf_bak vsftpd_conf_migrate.sh
[root@test924 vsftpd]# cat vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

附配置文件部分参数解析:
anonymous_enable=NO    #允许匿名用户访问为了安全选择关闭
local_enable=YES       # 允许本地用户登录
write_enable=YES      # 是否允许写入
local_umask=022       # 本地用户上传文件的umask
dirmessage_enable=YES    #为YES则进入目录时显示此目录下由message_file选项指定的文本文件(,默认为.message)的内容
xferlog_enable=YES       #开启日志
xferlog_std_format=YES      #标准格式
connect_from_port_20=YES
xferlog_file=/var/log/xferlog          #ftp日志目录
idle_session_timeout=6000         #设置客户端连接时间
data_connection_timeout=1200       #设置数据连接时间 针对上传,下载
chroot_list_file=/etc/vsftpd/chroot_list     #设置为YES则下面的控制有效
chroot_list_enable=YES           #若为NO,则记录在chroot_list_file所指定的文件(默认是/etc/vsftpd.chroot_list)中的用户将被chroot在登录后所在目录中,无法离开.如果为YES,则所记录的用户将不被chroot.这里YES.
chroot_local_user=YES
userlist_deny=NO               #若设置为YES则记录在userlist_file选项指定文件(默认是/etc/vsftpd.user_list)中的用户将无法login,并且将检察下面的userlist_deny选项
userlist_enable=YES               #若为NO,则仅接受记录在userlist_file选项指定文件(默认是/etc/vsftpd.user_list)中的用户的login请求.若为YES则不接受这些用户的请求.
userlist_file=/etc/vsftpd/user_list         #白名单
chroot_list_enable=YES
local_root=/var/ftp/pub             #根目录
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

由于匿名用户和本地用户登陆或多或少存在安全隐患,所有最好采用虚拟用户登录方式,这里介绍虚拟用户登录

1、创建虚拟用户登录
创建用户文件:注意,单数行为用户名,偶数行为密码
[root@test924 vsftpd]# vim vuser.list
[root@test924 vsftpd]# ls
ftpusers vsftpd.conf vsftpd_conf_migrate.sh
user_list vsftpd.conf_bak vuser.list
[root@test924 vsftpd]# cat vuser.list
ftpuser01
123456
node1
123456
node2
123456
明文太不安全,转为hash加密的密码,并对权限进行设置
[root@test924 vsftpd]# db_load -T -t hash -f vuser.list vuser.db
[root@test924 vsftpd]# ll
total 40
-rw------- 1 root root 125 Apr 1 12:55 ftpusers
-rw------- 1 root root 361 Sep 25 16:59 user_list
-rw-r--r-- 1 root root 245 Sep 25 16:56 vsftpd.conf
-rw------- 1 root root 5116 Apr 1 12:55 vsftpd.conf_bak
-rwxr--r-- 1 root root 338 Apr 1 12:55 vsftpd_conf_migrate.sh
-rw-r--r-- 1 root root 12288 Sep 25 17:00 vuser.db
-rw-r--r-- 1 root root 43 Sep 25 16:59 vuser.list
[root@test924 vsftpd]# cat vuser.db
?123456node2123456ftpuser01 ?}u??h^123456node1[root@test924 vsftpd]#
[root@test924 vsftpd]# file vuser.db
vuser.db: Berkeley DB (Hash, version 9, native byte-order)
[root@test924 vsftpd]# ll vuser.list
-rw-r--r-- 1 root root 43 Sep 25 16:59 vuser.list
[root@test924 vsftpd]# chmod 600 vuser.db
-rw------- 1 root root 12288 Sep 25 17:00 vuser.db

2、创建一个虚拟用户virtual,仅用于起始文件/var/ftproot,但不登录。。。注意,这里的/var/ftproot就是ftp根目录路径,注意根目录下的权限设置,否则后期使用会报550
[root@test924 vsftpd]# useradd -d /var/ftproot -s /sbin/nologin virtual
[root@test924 vsftpd]# id virtual
uid=1001(virtual) gid=1001(virtual) groups=1001(virtual)
[root@test924 vsftpd]# ls -ld /var/ftproot/
drwx------ 3 virtual virtual 78 Sep 25 17:08 /var/ftproot/
[root@test924 vsftpd]# chmod -Rf 755 /var/ftproot/

3、创建用于支持虚拟用户的PAM文件

[root@test924 vsftpd]# vim /etc/pam.d/vsftpd.vu
auth required pam_userdb.so db=/etc/vsftpd/vuser
account required pam_userdb.so db=/etc/vsftpd/vuser

4、修改ftp配置文件vsftpd.conf
[root@test924 vsftpd]# vim vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=NO
tcp_wrappers=YES
user_config_dir=/etc/vsftpd/vusers_dir
解析:
anonymous_enable=NO ###禁止匿名开放模式
local_enable=YES ###允许本地用户模式
guest_enable=YES ###开启虚拟用户模式
guest_username=virtual ###指定虚拟用户
pam_service_name=vsftpd.vu ###指定PAM文件
allow_writeable_chroot=YES ###允许对FTP根目录写入操作
user_config_dir=/etc/vsftpd/vusers_dir ###定义虚拟用户文件路径

5、设置虚拟用户在FTP服务器上的权限
[root@test924 vsftpd]# mkdir -p /etc/vsftpd/vuser_dir
[root@test924 vsftpd]# cd /etc/vsftpd/vuser_dir
[root@test924 vuser_dir]# vim node1
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
解析:
anon_upload_enable ###下载权限
anon_mkdir_write_enable ###创建写入权限
anon_other_write_enable ###其他写入权限

6、重启FTP服务
[root@test924 vsftpd]# systemctl restart vsftpd

服务器搭建完成。

在客户端下验证:
附客户端如果ftp命令报错。。请安装ftp服务。
[root@1node78 ~]# ftp 192.168.217.75
bash: ftp: command not found...
[root@1node78 ~]# yum install -y ftp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00
docker-ce-stable | 3.5 kB 00:00
epel | 4.7 kB 00:00
extras | 2.9 kB 00:00
k8s | 1.4 kB 00:00
updates | 2.9 kB 00:00
(1/2): epel/x86_64/updateinfo | 1.0 MB 00:01
(2/2): epel/x86_64/primary_db | 6.9 MB 00:03
Resolving Dependencies
--> Running transaction check
---> Package ftp.x86_64 0:0.17-67.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================
Package Arch Version Repository Size
===========================================================================
Installing:
ftp x86_64 0.17-67.el7 base 61 k

Transaction Summary
===========================================================================
Install 1 Package

Total download size: 61 k
Installed size: 96 k
Downloading packages:
ftp-0.17-67.el7.x86_64.rpm | 61 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ftp-0.17-67.el7.x86_64 1/1
Verifying : ftp-0.17-67.el7.x86_64 1/1

Installed:
ftp.x86_64 0:0.17-67.el7

Complete!

登录,输入正确的用户名密码进入
[root@1node78 ~]# ftp 192.168.217.75
Connected to 192.168.217.75 (192.168.217.75).
220 (vsFTPd 3.0.2)
Name (192.168.217.75:root): node1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ftp>
ftp>
ftp> mkdir test_file1
257 "/test_file1" created
ftp>
ftp>
ftp> rm test_file1
250 Remove directory operation successful.

ftp> ls
227 Entering Passive Mode (192,168,217,75,229,5).
150 Here comes the directory listing.
drwx------ 2 1001 1001 6 Sep 27 07:46 111.txt
-rw------- 1 1001 1001 269115 Sep 27 07:28 apache.png
-rw------- 1 1001 1001 12872547 Sep 27 02:18 latest-zh_CN.tar.gz
-rw------- 1 1001 1001 1228 Sep 27 07:23 lnmp.tar.gz
226 Directory send OK.
ftp> get lnmp.tar.gz
local: lnmp.tar.gz remote: lnmp.tar.gz
227 Entering Passive Mode (192,168,217,75,44,184).
150 Opening BINARY mode data connection for lnmp.tar.gz (1228 bytes).
226 Transfer complete.
1228 bytes received in 0.00176 secs (698.12 Kbytes/sec)
ftp> bye
221 Goodbye.

[root@1node78 ~]# ll

-rw-r--r-- 1 root root 1228 Sep 27 15:49 lnmp.tar.gz

附:常用ftp使用命令
put 上传文件命令
格式:put local-file [remote-file]
mput 批量上传命令
格式:mput local-files

get 下载文件命令
格式:get [remote-file] [local-file]
mget 批量下载命令      
格式:mget [remote-files]

----------------------------------------------------------------------------------------------------------------------------------------------------------

创建本地用户登陆
创建用户:
useradd ftpuser01
passwd ftpuser01
密码123456

设置核心配置文件
vim vsftpd.conf
1 anonymous_enable=NO
2 local_enable=YES
3 write_enable=YES
4 local_umask=022
5 dirmessage_enable=YES
6 xferlog_enable=YES
7 connect_from_port_20=YES
8 xferlog_std_format=YES
9 listen=NO
10 listen_ipv6=YES
11 pam_service_name=vsftpd
12 userlist_enable=YES
13 tcp_wrappers=YES

关闭防火墙
[root@test924 vsftpd]# systemctl stop firewalld
[root@test924 vsftpd]# systemctl disable firewalld

重启FTP服务
[root@test924 vsftpd]# systemctl restart vsftpd

ftp根目录路径为
/var/ftp/pub
注意访问权限,本地可以设置为777权限
[root@test924 ftp]# ll 
total 0
drwxr-xr-x 2 root root 6 Apr 1 12:55 pub

----------------------------------------------------------------------------------------------------------------------------------------------------------

CentOS7系统搭建FTP服务器的更多相关文章

  1. linux系统搭建ftp服务器及创建用户使用

    linux 系统下搭建ftp服务器 ftp是什么 FTP是 File Transfer Protocol 文件传输协议的英文名称,用于在Internet上控制文件的双向传输. 同时它也是一个应用程序. ...

  2. 腾讯云服务器linux centOS7.4 搭建ftp服务器 vsftpd

    腾讯云服务器linux centos 7.4 搭建ftp服务器 vsftpd 在centos 7.3测试也是OK的,其它版本没有实验 # 安装 vsftpd $ yum install vsftpd ...

  3. Centos7上搭建ftp服务器

    ftp服务器搭建 1.安装好centos系统,配好yum仓库 其中vsftpd源在这下载 http://rpmfind.net/linux/rpm2html/search.php?query=vsft ...

  4. 阿里云 CentOS7中搭建FTP服务器

    1配置 vsftpd-3.0.2-27.el7.x86_64 阿里云 centos 7.0 2 ftp工作模式 2.1 ftp通道 ftp工作会启动两个通道: 控制通道,数据通道 在ftp协议中,控制 ...

  5. Centos7安装搭建FTP服务器(最简便方法)

    简介: vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点. vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linu ...

  6. centos7上搭建ftp服务器(亲测可用)

    1.安装vsftpd 首先要查看你是否安装vsftp [root@localhost /]# rpm -q vsftpd vsftpd-3.0.2-10.el7.x86_64 (显示以上相关信息也就安 ...

  7. CentOS7种搭建FTP服务器

    1.安装vsftpd #首先要查看你是否安装vsftp [root@localhost /]# rpm -q vsftpd vsftpd-3.0.2-10.el7.x86_64             ...

  8. win7系统搭建FTP服务器

    工作需要,所以研究了一下. 1. 打开: 控制面板 -> 卸载程序 -> (左侧)打开或关闭windows功能 等个一小会,勾选如下图红色方框内的选项. 2. 开始 -> 搜索: I ...

  9. [linux系统]--搭建ftp服务器并且 创建用户 设置密码

    下面例子演示创建ftpuser 并且设置密码为ftpuser,ftpuser的目录为/root/ftpuser #!/bin/bash rpm -ivh vsftpd-2.2.2-21.el6.x86 ...

随机推荐

  1. Android开发在Activity外申请权限调用相机打开相册

    问题描述: 最近在项目中遇到一个需要调用相册和打开相机的需求,但是,在Android 6.0以后,调用相册属于危险权限,需要开发者动态获取,这就意味着我们申请权限是与Activity绑定的,但如果一个 ...

  2. Tom_No_02 Servlet向流中打印内容,之后在调用finsihResponse,调用上是先发送了body,后发送Header的解释

    上次在培训班学上网课的时候就发现了这个问题,一直没有解决,昨天又碰到了,2-3小时也未能发现点端倪,今早又仔细缕了下,让我看了他的秘密 1.Servlet向流中打印内容,之后在调用finsihResp ...

  3. Spring Cloud分区发布实践(3) 网关和负载均衡

    注意: 因为涉及到配置测试切换, 中间环节需按此文章操作体验, 代码仓库里面的只有最后一步的代码 准备好了微服务, 那我们就来看看网关+负载均衡如何一起工作 新建一个模块hello-gateway, ...

  4. OSPF多区域

    目录 一.OSPF的多区域 1.1 生成OSPF多区域的原因 1.2 路由器的类型 1.3 区域的类型 二.链路状态数据库 2.1 链路状态数据库的组成 2.2链路状态通告 三.OSPF多区域配置 四 ...

  5. Java方法——递归

    递归(栈)  package method; ​ public class Demon04 {        //递归思想    public static void main(String[] ar ...

  6. Flutter 中的动画

    Flutter 中动画的创建有很多种, 需要根据具体的需求选择不同的动画.如果只是简单的布局等的动画直接使用最简单的隐式动画就可以了,因为隐式动画是由框架控制的,所以仅仅只需要更改变需要变化属性就可以 ...

  7. 1.9 货仓选址问题——Python

    题目描述 在一条数轴上有 N 家商店,它们的坐标分别为 A1~AN. 现在需要在数轴上建立一家货仓,每天清晨,从货仓到每家商店都要运送一车商品. 为了提高效率,求把货仓建在何处,可以使得货仓到每家商店 ...

  8. 0基础学小程序----day1

    17的书,那时候微信小程序开发程序还是v0.01 19年都v1.02了.位置都不一样了,枯了 技术准备:WXML使用方法类似于HTML,(都不会) 自己的样式语言WXSS兼容了CSS(都不会) 使用J ...

  9. 【笔记】随机森林和Extra-Trees

    随机森林和Extra-Trees 随机森林 先前说了bagging的方法,其中使用的算法都是决策树算法,对于这样的模型,因为具有很多棵树,而且具备了随机性,那么就可以称为随机森林 在sklearn中封 ...

  10. AttributeError: module 'numpy' has no attribute 'num'

    AttributeError: module 'numpy' has no attribute 'num' 写在前面 总的来说,先看看自己用的计算方式是不是写对了先,多个一起使用的话记得都看看 通过想 ...