FTP服务器的配置

FTP服务器

文件传输协议(File Transfer Protocol)是用于在网络上进行文件传输的一套标准协议,使用客户/服务器模式。专门用来传输文件的协议

FTP服务器工作原理

FTP是一种在互联网中进行文件传输的协议,基于客户端/服务器模式,默认使用20、21号端口,其中端口20(数据端口)用于进行数据传输,端口21(命令端口)用于接受客户端发出的相关FTP命令与参数
在这里插入图片描述
FTP服务器允许用户以三种认证模式登录到FTP服务器上
匿名开放模式:是一种最不安全的认证模式,任何人都可以无需密码验证而直接登录到FTP服务器。
本地用户模式:是通过Linux系统本地的账户密码信息进行认证的模式,相较于匿名开放模式更安全,配置起来也很简单。
虚拟用户模式:是这三种模式中最安全的一种认证模式,它需要为FTP服务单独建立用户数据库文件,虚拟出用来进行口令验证的账户信息,而这些账户信息在服务器系统中实际上是不存在的

FTP服务器协议

FTP服务器是按照FTP协议在互联网上提供文件存储和访问服务的主机,FTP客户端则是向服务器发送连接请求,以建立数据传输链路的主机。FTP协议有下面两种工作模式
主动模式:FTP服务器主动向客户端发起连接请求
被动模式:FTP服务器等待客户端发起连接请求(FTP的默认工作模式)

常见的FTP服务器软件

Serv-U #Windows
FileZilla #Windows
VsFTP #Linux

常见的FTP的客户端

FileZilla
WinScp
FlashFTP
SecureCRT
CuteFTP

VSFTP服务器的安装及配置

1.关闭防火墙&Selinux

[root@linux ~]# systemctl stop firewalld
[root@linux ~]# setenforce 0
setenforce: SELinux is disabled
[root@linux ~]# getenforce 
Disabled

2.安装VsFTP服务器及客户端

[root@linux ~]# yum install vsftpd ftp -y
Loaded plugins: fastestmirror
c7                                                         | 3.6 kB  00:00:00     
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ftp.x86_64 0:0.17-67.el7 will be installed
---> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================
 Package           Arch              Version                  Repository     Size
==================================================================================
Installing:
 ftp               x86_64            0.17-67.el7              c7             61 k
 vsftpd            x86_64            3.0.2-22.el7             c7            169 k

Transaction Summary
==================================================================================
Install  2 Packages

Total download size: 230 k
Installed size: 444 k
Downloading packages:
----------------------------------------------------------------------------------
Total                                                663 kB/s | 230 kB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : vsftpd-3.0.2-22.el7.x86_64                                     1/2 
  Installing : ftp-0.17-67.el7.x86_64                                         2/2 
  Verifying  : ftp-0.17-67.el7.x86_64                                         1/2 
  Verifying  : vsftpd-3.0.2-22.el7.x86_64                                     2/2 

Installed:
  ftp.x86_64 0:0.17-67.el7              vsftpd.x86_64 0:3.0.2-22.el7             

Complete!

3.匿名访问模式配置
#开放匿名用户的上传、下载文件的权限,以及让匿名用户创建、删除、更名文件的权限。(注:此项不建议在生产环境使用。)

[root@linux ~]# vi /etc/vsftpd/vsftpd.conf
# 在vsftpd.conf文件中添加下面三句(若能在注释了的文本中找到,也可取消注释):
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES

[root@linux ~]# systemctl restart vsftpd			#重启服务
[root@linux ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

测试:

[root@web ~]# ftp 192.168.130.128
Connected to 192.168.130.128 (192.168.130.128).
220 (vsFTPd 3.0.2)
Name (192.168.130.128:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> pwd
257 "/pub"
ftp> mkdir ftp_dir
550 Create directory operation failed.
#使用另一台客户机进行ftp测试,发现可以匿名访问,但是使用匿名访问时无法创建目录

#此时可以在服务端更改pub目录的权限
[root@linux ~]# chown -Rf ftp /var/ftp/pub/

#再次测试
[root@web ~]# ftp 192.168.130.128
Connected to 192.168.130.128 (192.168.130.128).
220 (vsFTPd 3.0.2)
Name (192.168.130.128:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> pwd
257 "/pub"
ftp> mkdir ftp_dir
257 "/pub/ftp_dir" created			#创建成功
ftp> ls
227 Entering Passive Mode (192,168,130,128,77,21).
150 Here comes the directory listing.
drwx------    2 14       50              6 Nov 28 08:01 ftp_dir
226 Directory send OK.			#查询,创建目录存在

4.本地用户模式

[root@linux ~]# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO			#更改此项的参数为NO
[root@linux ~]# systemctl restart vsftpd			#重启服务

测试:

[root@web ~]# ftp 192.168.130.128
Connected to 192.168.130.128 (192.168.130.128).
220 (vsFTPd 3.0.2)
Name (192.168.130.128:root): root
530 Permission denied.
Login failed.			#测试使用root用户登录失败
#vsftpd服务所在目录中存放着两个用户名单ftpusers,user_list,出于安全原因,root默认不允许登录,编辑这两个文件注释root即可。同时可以创建一个新用户用于测试。
[root@linux vsftpd]# vi ftpusers
  1 # Users that are not allowed to login via ftp
  2 #root
  3 bin
  4 daemon
  5 adm
  6 lp
  7 sync
  8 shutdown
  9 halt
 10 mail
 11 news
 12 uucp
 13 operator
 14 games
 15 nobody
[root@linux vsftpd]# vi user_list
  1 # vsftpd userlist
  2 # If userlist_deny=NO, only allow users in this file
  3 # If userlist_deny=YES (default), never allow users in this file, and
  4 # do not even prompt for a password.
  5 # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
  6 # for users that are denied.
  7 #root
  8 bin
  9 daemon
 10 adm
 11 lp
 12 sync
 13 shutdown
 14 halt
 15 mail
 16 news
 17 uucp
 18 operator
 19 games
 20 nobody
[root@linux vsftpd]# systemctl restart vsftpd

5.VsFTP高级应用,虚拟用户模式
#虚拟用户模式是这三种模式中最安全的一种认证模式,配置复杂

[root@linux vsftpd]# vi /etc/vsftpd/vuser.list
  1 user1
  2 123456
  3 user2
  4 123456

db_load命令用哈希(hash)算法将原始的明文信息文件转换成数据库文件

[root@linux vsftpd]# db_load -T -t hash -f vuser.list vuser.db
[root@linux vsftpd]# file vuser.db 
vuser.db: Berkeley DB (Hash, version 9, native byte-order)
[root@linux vsftpd]# chmod 600 vuser.db
[root@linux vsftpd]# rm -rf vuser.list

创建vsftpd服务程序用于存储文件的根目录以及虚拟用户映射的系统本地用户。FTP服务用于存储文件的根目录指的是当虚拟用户登录后所访问的默认位置。

[root@linux vsftpd]# useradd -d /var/ftproot -s /sbin/nologin virtual
[root@linux vsftpd]# ls -ld /var/ftproot/
drwx------ 2 virtual virtual 62 Nov 28 17:14 /var/ftproot/
[root@linux vsftpd]# chmod -Rf 755 /var/ftproot/

建立用于支持虚拟用户的PAM文件
#PAM是一组安全机制的模块,系统管理员可以用来轻易地调整服务程序的认证方式

[root@linux vsftpd]# vi /etc/pam.d/vsftpd.vu 
  1 auth required pam_userdb.so db=/etc/vsftpd/vuser
  2 account required pam_userdb.so db=/etc/vsftpd/vuser
[root@linux vsftpd]# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=No			#更改参数为NO
guest_enable=YES				#添加以下四条参数
guest_username=virtual
allow_writeable_chroot=YES
pam_service_name=vsftpd.vu

为虚拟用户创建不同的权限

[root@linux vsftpd]# mkdir /etc/vsftpd/vusers_dir
[root@linux vsftpd]# cd /etc/vsftpd/vusers_dir/
[root@linux vsftpd]# touch user1
[root@linux vsftpd]# vi user1
  1 anon_upload_enable=YES
  2 anon_mkdir_write_enable=YES
  3 anon_other_write_enable=YES
[root@linux vusers_dir]# vi /etc/vsftpd/vsftpd.conf
user_config_dir=/etc/vsftpd/vusers_dir			#添加本条语句
[root@linux vusers_dir]# systemctl restart vsftpd

用user1和user2分别进行测试

[root@web ~]# ftp 192.168.130.128
Connected to 192.168.130.128 (192.168.130.128).
220 (vsFTPd 3.0.2)
Name (192.168.130.128:root): user1  
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,130,128,214,181).
150 Here comes the directory listing.
226 Directory send OK.
ftp> mkdir user1
257 "/user1" created
ftp> touch user1
?Invalid command
ftp> ls
227 Entering Passive Mode (192,168,130,128,166,153).
150 Here comes the directory listing.
drwx------    2 10018    10018           6 Nov 28 09:44 user1
226 Directory send OK.
[root@web ~]# ftp 192.168.130.128
Connected to 192.168.130.128 (192.168.130.128).
220 (vsFTPd 3.0.2)
Name (192.168.130.128:root): user2
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,130,128,123,173).
150 Here comes the directory listing.
drwx------    2 10018    10018           6 Nov 28 09:44 user1
226 Directory send OK.
ftp> mkdir user2
257 "/user2" created
ftp> touch user2
?Invalid command
ftp> ls
227 Entering Passive Mode (192,168,130,128,46,98).
150 Here comes the directory listing.
drwx------    2 10018    10018           6 Nov 28 09:44 user1
drwx------    2 10018    10018           6 Nov 28 09:46 user2
226 Directory send OK.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值