ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux网络文件共享服务——FTP服务

2021-01-31 12:32:25  阅读:154  来源: 互联网

标签:ftp enable FTP 文件共享 vsftpd Linux YES root


一、存储类型的介绍

(以下介绍来自个人理解,有不详细或者错误的地方麻烦指正)
NAS(Network-Attached Storage)网络附加存储:通过以太网网络把存储服务器上的文件夹或者文件共享到其他客户端使用。
SAN(Storage AreaNetwork)存储区域网络:通过光纤或者以太网,将存储设备和服务器连接起来,最后形成一个  存储的网络 
DAS(Direct-Attached Storage)直连式附加存储:把存储设备直接连接到服务器上使用。
可参照此网址介绍理解:https://www.bilibili.com/read/cv866693/

二、存储类型的比较

存储类型比较
存储类型NASSANDAS
传输类型IPFC(光纤),SAS,IPFC,SCSI
数据类型文件数据数据块数据块
应用典型网络文件服务器数据库应用任何
优点不占用应用服务器资源,广泛支持操作系统,扩展较容易,即插即用高扩展性,方便管理,数据集中,高可用性磁盘与服务器分离便于管理
缺点不适合存储量大的块级应用,数据备份及恢复占用网络带宽【相当于一个人(NAS)干着两个人的工作(备份和恢复)拿着一个人的工资(带宽)】成本高,相对NAS安装复杂连接距离局限,扩展性有限,数据分散,不易共享,存储空间利用率低

三、FTP服务

1.FTP介绍

FTP(文件传输协议)是TCP / IP协议组中的协议之一。他最主要的功能是在服务器与客户端之间进行文件的传输。FTP就是实现两台计算机之间的副本,从远程计算机复制文件至自己的计算机上,称为“Download(下载)”文件。将文件从自己计算机中拷贝至远程计算机上,则称为“upload(上传)”文件。这个协议使用的是明码传输方式,FTP是一个C / S类型的软件,FTP监听TCP端口号为21,数据端口为20。(我们所用的软件叫vsftp(very secure FTP daemon)翻译过来叫 非常安全的FTP守护程序)

默认传输的格式是:二进制或者文本(ftp默认为二进制传输)

2.应用场景

① 下载服务器

② 文件服务器

③ 上传服务器

3.FTP的权限

FTP除了提供文件的传输服务之外,还提供了几个主要的功能;

不同等级的用户身份:本地用户,虚拟用户,匿名用户

本地用户:是系统中真实存在的用户

虚拟用户:相当于windows上的访客用户

匿名用户:就是可以不使用任何账号,任何人都可以登录

三者用户的权限相差较大,比如本地用户的权限要比虚拟用户和匿名用户的权限要完整,而匿名用户的权限比较低,三者在线使用的ftp命令也会根据权限大小有限制

4.FTP服务的工作模式

FTP有两种工作模式

①主动模式(默认):客户端先从自己的随机端口(1024-65535)与FTP服务器的21端口进行连接(确定客户端使用1024-65535之间的哪个端口进行连接),通过这个端口发送指令,FTP服务器再收到命令后通过20端口传输数据到客户端确认的随机端口(已经确认的传输端口)。

②被动模式:客户端先从自己的随机端口(1024-65535)与FTP服务器的21端口进行连接(客户端使用被动连接时FTP服务会返回一个高位端口(ftp的大于1024的端口)告知客户端使用这个端口进行传输),然后FTP服务和客户端都使用的高位端口进行数据传输(不再是20端口)

5.安装部署FTP服务(vsftpd)

配置介绍:centos7.5 3.10.0-1160.11.1.el7.x86_64,请关闭服务器和SELinux(或者firewalld开端口也行)

#安装命令
[root@centos7 ~]# yum -y install vsftpd

#vsftpd启动
[root@centos7 ~]# systemctl start vsftpd

#查看是否启动成功
[root@centos7 ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-01-31 11:28:21 CST; 40s ago
  Process: 1865 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 1866 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─1866 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Jan 31 11:28:21 centos7.5 systemd[1]: Starting Vsftpd ftp daemon...
Jan 31 11:28:21 centos7.5 systemd[1]: Started Vsftpd ftp daemon.

6.相关配置文件路径

#vsftpd的主配置文件:

/etc/vsftpd/vsftpd.conf

#默认登录目录:

/ var / ftp /

#FTP日志文件路径:

/ var / log / xferlog

7.主配置文件详解

# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO   #匿名用户访问,YES是允许,NO是拒绝
#
# Uncomment this to allow local users to log in.
# 请设置开启布尔值ftp_home_dir为ON
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES     #本地用户登录,YES是允许,NO是拒绝.默认访问的是本地用户家目录
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES     #允许本地用户上传
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022      # 上传的权限是022,使用的是umask权限。对应的目录是755,文件是644
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES     # 开启匿名用户上传功能,默认是拒绝的
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES # 开启匿名用户创建文件或文件夹权限
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES      # 开启目录欢迎消息,一般对命令行登陆有效
#
# Activate logging of uploads/downloads.
xferlog_enable=YES         # 开启上传和下载日志记录功能
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES        #使用标准模式
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES        # 声明匿名用户上传文件的所有者,允许更改匿名用户上传文件的所有者
#chown_username=whoever  #所有者为whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog    # 日志文件路径
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES     # 日志文件采用标准格式
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600        # 会话超时时间(如果停止太久没有命令ftp可能会断开连接)
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120     # 数据传输超时时间(尽量不要传输过大的文件以免数据中断丢失)
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure            # FTP子进程管理用户
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES       # 是否允许客户端发起“async ABOR”请求,该操作是不安全的默认禁止。
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES    # 该选项用于指定是否允许上传时以ASCII模式传输数据
#ascii_download_enable=YES    #该选项用于指定是否允许下载时以ASCII模式传输数据
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.    # FTP文本界面登陆欢迎词
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES    # 是否开启拒绝的Email功能
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails    # 指定保存被拒接的Email地址的文件
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
# 是否开启对本地用户chroot的限制,YES为默认所有用户都不能切出家目录,NO代表默认用户都可以切出家目录
# 设置方法类似于:YES拒绝所有,允许个别    NO  允许所有拒绝个别
#chroot_local_user=YES
#开启特例列表
#chroot_list_enable=YES
# (default follows)
# 如果chroot_local_user的值是YES则该文件中的用户是可以切出家目录,如果是NO,该文件中的用户则不能切出家目录
# 一行一个用户。
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES        # 是否开启ls 递归查询功能 ls -R
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO    # 是否开启ftp独立模式在IPV4
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
# 是否开启ftp独立模式在ipv6
listen_ipv6=YES

#启用pam模块验证
pam_service_name=vsftpd
#是否开启userlist功能.是否启用用户列表功能
userlist_enable=YES
#用户列表路径
#userlist_file=/etc/vsftpd/user_list
#是否拒绝userlist功能
#userlist_deny=NO
#对ftp访问安全机制(默认开启)
tcp_wrappers=YES

通过配置文件的分析,FTP可以匿名访问,本地用户可以下载和上传。如果允许匿名用户登录的话需要将开启 anonymous_enable = YES,然后重新启动服务

我们可以通过修改配置文件的内容立即配置FTP的相关登陆情况。(大家可以自己试试)

8.实践

①实现匿名用户访问(图形化)匿名访问默认目录在ftp下的pub目录

②文本界面ftp访问

#登录失败提示(文本界面登录可以使用lftp或者ftp,yum安装一个就好)
[root@centos7 ~]# ftp 192.168.2.13
Connected to 192.168.2.13 (192.168.2.13).
220 (vsFTPd 3.0.2)
Name (192.168.2.13:root): 123
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.

#FTP服务状态码:
#    1XX:信息 125:数据连接打开
#   2XX:成功类状态 200:命令OK 230:登录成功
#    3XX:补充类 331:用户名OK
#    4XX:客户端错误 425:不能打开数据连接
#    5XX:服务器错误 530:不能登录用户认证:


#登录成功
[root@centos7 ~]# ftp 192.168.2.13
Connected to 192.168.2.13 (192.168.2.13).
220 (vsFTPd 3.0.2)
Name (192.168.2.13:root): ftp
331 Please specify the password.
Password:        #密码为空
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
#在ftp界面可以使用ftp命令进行控制
ftp> help   #帮助命令 可以查看FTP的可使用命令
Commands may be abbreviated.  Commands are:

!		debug		mdir		sendport	site
$		dir		mget		put		size
account		disconnect	mkdir		pwd		status
append		exit		mls		quit		struct
ascii		form		mode		quote		system
bell		get		modtime		recv		sunique
binary		glob		mput		reget		tenex
bye		hash		newer		rstatus		tick
case		help		nmap		rhelp		trace
cd		idle		nlist		rename		type
cdup		image		ntrans		reset		user
chmod		lcd		open		restart		umask
close		ls		prompt		rmdir		verbose
cr		macdef		passive		runique		?
delete		mdelete		proxy		send
ftp> pwd
257 "/"   
#通过pwd命令查看当前路径  注意这里显示的是FTP的根目录
ftp> bye
221 Goodbye.
#退出使用bye命令

#本地用户登录
[root@centos7 ~]# useradd test  #先添加一个本地用户
[root@centos7 ~]# passwd test   #添加密码
Changing password for user test.
New password:               #输入密码
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:            #重复密码
passwd: all authentication tokens updated successfully.
[root@centos7 ~]# ll /home/        #查看添加用户的目录
total 0
drwx------. 2 test test 62 Jan 31 12:10 test

#登录
[root@centos7 ~]# ftp 192.168.2.13
Connected to 192.168.2.13 (192.168.2.13).
220 (vsFTPd 3.0.2)
Name (192.168.2.13:root): test
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,2,13,188,108).
150 Here comes the directory listing.
226 Directory send OK.
ftp> mkdir 123  #创建目录
257 "/home/test/123" created
ftp> ls
227 Entering Passive Mode (192,168,2,13,113,192).
150 Here comes the directory listing.
drwxr-xr-x    2 1001     1001            6 Jan 31 04:12 123
-rw-------    1 0        0            5171 Jan 31 04:13 vsftpd.conf
226 Directory send OK.
ftp> pwd
257 "/home/test"   #所在位置
ftp> 

!+linux命令   #执行系统命令
!ls /opt  #显示linux系统中/opt目录下的内容
ftp> !ls /opt
dhcp  dns  rh

lcd #linux系统中的当前目录
lcd /root  #将linux系统中的当前目录切换到/root下
ftp> lcd /root
Local directory now /root

还有安全设置虚拟用户配置后面有时间了再补充,今天先写到这里,如果有不到位的地方麻烦指出,谢谢观看!
 

标签:ftp,enable,FTP,文件共享,vsftpd,Linux,YES,root
来源: https://blog.csdn.net/qq_45925514/article/details/113458021

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有