CentOS7系统搭建FTP服务器
创建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服务器的更多相关文章
- linux系统搭建ftp服务器及创建用户使用
linux 系统下搭建ftp服务器 ftp是什么 FTP是 File Transfer Protocol 文件传输协议的英文名称,用于在Internet上控制文件的双向传输. 同时它也是一个应用程序. ...
- 腾讯云服务器linux centOS7.4 搭建ftp服务器 vsftpd
腾讯云服务器linux centos 7.4 搭建ftp服务器 vsftpd 在centos 7.3测试也是OK的,其它版本没有实验 # 安装 vsftpd $ yum install vsftpd ...
- Centos7上搭建ftp服务器
ftp服务器搭建 1.安装好centos系统,配好yum仓库 其中vsftpd源在这下载 http://rpmfind.net/linux/rpm2html/search.php?query=vsft ...
- 阿里云 CentOS7中搭建FTP服务器
1配置 vsftpd-3.0.2-27.el7.x86_64 阿里云 centos 7.0 2 ftp工作模式 2.1 ftp通道 ftp工作会启动两个通道: 控制通道,数据通道 在ftp协议中,控制 ...
- Centos7安装搭建FTP服务器(最简便方法)
简介: vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点. vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linu ...
- centos7上搭建ftp服务器(亲测可用)
1.安装vsftpd 首先要查看你是否安装vsftp [root@localhost /]# rpm -q vsftpd vsftpd-3.0.2-10.el7.x86_64 (显示以上相关信息也就安 ...
- CentOS7种搭建FTP服务器
1.安装vsftpd #首先要查看你是否安装vsftp [root@localhost /]# rpm -q vsftpd vsftpd-3.0.2-10.el7.x86_64 ...
- win7系统搭建FTP服务器
工作需要,所以研究了一下. 1. 打开: 控制面板 -> 卸载程序 -> (左侧)打开或关闭windows功能 等个一小会,勾选如下图红色方框内的选项. 2. 开始 -> 搜索: I ...
- [linux系统]--搭建ftp服务器并且 创建用户 设置密码
下面例子演示创建ftpuser 并且设置密码为ftpuser,ftpuser的目录为/root/ftpuser #!/bin/bash rpm -ivh vsftpd-2.2.2-21.el6.x86 ...
随机推荐
- ThinkPHP5 5.0.22/5.1.29 远程代码执行漏洞
http://192.168.49.2:8080/index.php?s=/Index/\think\app/invokefunction&function=call_user_func_ar ...
- Mac使用Charles抓取ios手机APP中的https请求
1.配置Http代理 Port为监听端口号,默认为8888,勾选Enable transparent HTTP proxying,接着勾选SOCKS proxy,可以监听Socks请求 2.安装Cha ...
- GooseFS助力大数据业务数倍提升计算能力
前言 GooseFS是由腾讯云推出的一款分布式缓存方案,主要针对包括需要缓存加速的数据湖业务场景,提供基于对象存储COS服务的近计算端数据加速层. GooseFS 基于开源大数据缓存方案 Alluxi ...
- MySQL 中删除的数据都去哪儿了?
不知道大家有没有想过下面这件事? 我们平时调用 DELETE 在 MySQL 中删除的数据都去哪儿了? 这还用问吗?当然是被删除了啊 那么这里又有个新的问题了,如果在 InnoDB 下,多事务并发的情 ...
- 三年Android开发,月薪一万二,不敢跳槽,每天都很焦虑
在我们的身边,存在一个普遍现象:很多人从事Android开发工作多年,走过的弯和坎,不计其数,经历的心酸难与外人道也.可是技术确难以提升.止步不前,薪资也只能看着别人水涨船高,自己却没有什么起色. 虽 ...
- C++实现链表的相关基础操作
链表的相关基础操作 # include <iostream> using namespace std; typedef struct LNode { int data; //结点的数据域 ...
- Linux下使用pure-ftpd建立匿名ftp访问
by 无若 (一)ubuntu14.04下使用pure-ftpd建立匿名ftp访问 1.安装apt-get install pure-ftpd 2.修改配置nano /etc/pure-ftpd/co ...
- Azure Bicep 开发利器
Bicep 是一种用于声明式部署Azure资源的领域特定语言.它的目标是通过更清晰的语法.改进的类型安全性.以及对模块化和代码重用的更好支持,彻底简化编写体验. Bicep 其实是对 ARM 模板的透 ...
- "image watch" for QtCreator
Image Watch Image Watch 是Visual Studio的一个插件,用来在C++ 调试时显示内存中的位图图像.可以直观的看到图像的变化而不用添加额外的显示代码.其内建了对OpenC ...
- Windows下NodeJS安装与npm环境变量配置
node.js下载:https://nodejs.org/en/download/ 参考:https://www.jianshu.com/p/812de13f1276 1.安装过程基本直接" ...