FTP的全称是File Transfer Protocol(文件传输协议),就是专门用来传输文件的协议.它工作在OSI模型的第七层,即是应用层,使用TCP传输而不是UDP.这样FTP客户端和服务器建立连接前就要经过一个"三次握手"的过程.FTP服务还有一个非常重要的特点是它可以独立于平台.
LINUX下实现FTP服务的软件很多,最常见的有vsftpd,Wu-ftpd和Proftp等.Red Hat Enterprise Linux中默认安装的是vsftpd.
通常,访问FTP服务器时需要经过验证,只有经过了FTP服务器的相关验证,用户才能访问和传输文件.vsftpd提供了3种ftp登录形式:
(1)anonymous(匿名帐号)
使用anonymous是应用广泛的一种FTP服务器.如果用户在FTP服务器上没有帐号,那么用户可以以anonymous为用户名,以自己的电子邮件地址为密码进行登录.当匿名用户登录FTP服务器后,其登录目录为匿名FTP服务器的根目录/var/ftp.为了减轻FTP服务器的负载,一般情况下,应关闭匿名帐号的上传功能.
(2)real(真实帐号)
real也称为本地帐号,就是以真实的用户名和密码进行登录,但前提条件是用户在FTP服务器上拥有自己的帐号.用真实帐号登录后,其登录的目录为用户自己的目录,该目录在系统建立帐号时系统就自动创建.
(3)guest(虚拟帐号)
如果用户在FTP服务器上拥有帐号,但此帐号只能用于文件传输服务,那么该帐号就是guest,guest是真实帐号的一种形式,它们的不同之处在于,geust登录FTP服务器后,不能访问除宿主目录以外的内容.
下面就对其详细介绍.
一.安装与启动vsftpd
先使用命令查看是否安装.
![](https://i-blog.csdnimg.cn/blog_migrate/5edf5f49ffaf1141e40587e7d38633e2.jpeg)
可看到安装了版本为2.0.1.如果没有安装可在桌面上选择"应用程序"/"系统设置"添加/删除应用程序"命令.来安装FTP软件包.
安装和配置好vsftpd软件包后,需要启动FTP服务器才能使用.启动方法有以下两种:
1.使用图形化方式启动,选择"应用程序"/系统设置/服务器设置/服务.可看到vsftpd,打上勾,开始启动.
2.在终端窗口用命令进行启动.
![](https://i-blog.csdnimg.cn/blog_migrate/be3c96b6b4b829b352f363554fff0569.jpeg)
还可以使用service命令.
![](https://i-blog.csdnimg.cn/blog_migrate/7b86f0ffa611ef867434a4c0331c61a1.jpeg)
二.FTP相关配置文件说明
其相关配置文件有/etc/vsftpd/vsftpd.conf, /etc/vsftpd.ftpusers, /etc/vsftpd.user_list,在配置FTP服务器时,主要是修改这些文件中的相关语句.
1.vsftpd.conf文件说明
# 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=YES //是否允许anonymous登录FTP服务器,默认是允许的.
#
# Uncomment this to allow local users to log in.
local_enable=YES //是否允许本地用户登录FTP服务器,默认是允许
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES //是否允许用户具有在FTP服务器文件中执行写的权限,默认是允许
#
# 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,默认是077
#
# 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.
#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 //是否允许匿名账户在FTP服务器中创建目录
#
# 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 //启用FTP数据端口的连接请求
#
# 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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log //设置日志文件的文件名和存储路径,这是默认的
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES//是否使用标准的ftpd xferlog日志文件格式
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600 //设置空闲的用户会话中断时间,默认是10分钟
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120//设置数据连接超时时间,默认是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
#
# 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
#
# 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.
# Beware that turning on ascii_download_enable enables malicious remote parties
# to consume your I/O resources, by issuing the command "SIZE /big/file" in
# ASCII mode.
# These ASCII options are split into upload and download because you may wish
# to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
# without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
# on the client anyway..
#ascii_upload_enable=YES
#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
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# 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().
#chroot_list_enable=YES //如果希望用户登录后不能切换到自己目录以外的其它目录,需要设置该项,如果设置chroot_list_enable=YES,那么只允许/etc/vsftpd.chroot_list中列出的用户具有该功能.如果希望所有的本地用户都执行者chroot,可以增加一行:chroot_local_user=YES
# (default follows)
#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
#
# 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=YES //是否允许anonymous登录FTP服务器,默认是允许的.
#
# Uncomment this to allow local users to log in.
local_enable=YES //是否允许本地用户登录FTP服务器,默认是允许
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES //是否允许用户具有在FTP服务器文件中执行写的权限,默认是允许
#
# 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,默认是077
#
# 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.
#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 //是否允许匿名账户在FTP服务器中创建目录
#
# 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 //启用FTP数据端口的连接请求
#
# 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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log //设置日志文件的文件名和存储路径,这是默认的
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES//是否使用标准的ftpd xferlog日志文件格式
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600 //设置空闲的用户会话中断时间,默认是10分钟
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120//设置数据连接超时时间,默认是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
#
# 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
#
# 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.
# Beware that turning on ascii_download_enable enables malicious remote parties
# to consume your I/O resources, by issuing the command "SIZE /big/file" in
# ASCII mode.
# These ASCII options are split into upload and download because you may wish
# to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
# without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
# on the client anyway..
#ascii_upload_enable=YES
#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
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# 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().
#chroot_list_enable=YES //如果希望用户登录后不能切换到自己目录以外的其它目录,需要设置该项,如果设置chroot_list_enable=YES,那么只允许/etc/vsftpd.chroot_list中列出的用户具有该功能.如果希望所有的本地用户都执行者chroot,可以增加一行:chroot_local_user=YES
# (default follows)
#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
pam_service_name=vsftpd //设置PAM认证服务的配置文件名称,该文件存放在/etc/pam.d/目录下.
userlist_enable=YES //用户列表中的用户是否允许登录FTP服务器,默认是不允许
#enable for standalone mode
listen=YES //使vsftpd 处于独立启动模式
tcp_wrappers=YES //使用tcp_wrqppers作为主机访问控制方式
userlist_enable=YES //用户列表中的用户是否允许登录FTP服务器,默认是不允许
#enable for standalone mode
listen=YES //使vsftpd 处于独立启动模式
tcp_wrappers=YES //使用tcp_wrqppers作为主机访问控制方式
2.vsftpd.ftpusers文件说明
这个文件是用来记录"不允许"登录到FTP服务器的用户,通常是一些系统默认的用户.
下面是该文件中默认的不允许登录的名单:
# Users that are not allowed to login via ftp
root //默认情况下,root和它以下的用户是不允许登录FTP服务器的.可以将不允许登录的用户添加到这里来.但切记每个用户都要单独占用一行.
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
root //默认情况下,root和它以下的用户是不允许登录FTP服务器的.可以将不允许登录的用户添加到这里来.但切记每个用户都要单独占用一行.
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
3.vsftpd.user_list文件说明
其实它的内容跟上面那个文件内容一样,只是在系统对文件vsftpd.conf 进行检测时,会检测到"userlist_deny=YES",因此这个文件必须存在.下面是这个文件的内容.
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd.ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd.ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
三.配置FTP服务器
下面具体分两类来进行详细介绍,一类是匿名帐号服务器的各种设置方法,另一类是在FTP服务咕嘟上拥有真实帐号的FTP服务器的各种配置方法.
1.匿名帐号服务器
1)配置一个简单的匿名帐号服务器
为了防止配置过程中出现错误,一般应把原配置文件/etc/vsftpd/vsftpd.conf复制一份到别的目录中,一旦配置后出现问题解决不了,还可以把原配置文件复制回来.
下面修改文件/etc/vsftpd/vsftpd.conf如下:
![](https://i-blog.csdnimg.cn/blog_migrate/ebfe4ca11d8aaa0496eccdc3d1d7a2b6.jpeg)
设置允许anonymous登录FTP服务器,允许本地帐号登录,允许本地帐号有写权限.
![](https://i-blog.csdnimg.cn/blog_migrate/1b7a9f4e5481409b60203849a94188f1.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/083f531cf04aeaf2bd904a90f6c46c4d.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/dd421d1b8132f73147376450ff18a7fc.jpeg)
用户列表里的用户不允许登录FTP服务器.
配置好后,需要重新启动vsftpd
匿名帐号可以是ftp或anonymous,口令一个E-Mail地址.
![](https://i-blog.csdnimg.cn/blog_migrate/2213fefb609976dac87192db900e6dd8.jpeg)
这里可看到有个默认的FTP目录.
下面进行测试
![](https://i-blog.csdnimg.cn/blog_migrate/6f2685131d0347ac282dcb9a66fff2fb.jpeg)
可看到匿名帐号输入错误时是不能登录的.输入一个电子邮件地址作为密码也是不能登录.
![](https://i-blog.csdnimg.cn/blog_migrate/61e4a5a1a0e485ee06f813ae2679c9ef.jpeg)
更改用户名,然后输入一个电子邮件地址作为密码.,登录成功.
![](https://i-blog.csdnimg.cn/blog_migrate/f416b3f6111245cd75a447c52b4efc07.jpeg)
查看一下FTP帐号在FTP服务器上的目录,然后退出登录.
![](https://i-blog.csdnimg.cn/blog_migrate/f64a22b31f94fda4f82ef3793fe1d20e.jpeg)
用匿名帐号登录,并输入一个电子邮件地址作为密码.登录成功.
![](https://i-blog.csdnimg.cn/blog_migrate/9e119cb13632e38cdf4587bcb4dc59e5.jpeg)
列出匿名帐号在FTP服务器上的目录,然后更改到pub目录下.
![](https://i-blog.csdnimg.cn/blog_migrate/b467ef17ffefec25b531349f3c45088d.jpeg)
这是pud目录下的内容.
![](https://i-blog.csdnimg.cn/blog_migrate/5022e790fbe41ee28a118c740de9cf1e.jpeg)
可看到匿名帐号可以下载文件.
![](https://i-blog.csdnimg.cn/blog_migrate/6b6d32883f1d4dacb55dace1ee75c53e.jpeg)
同样可以下载
![](https://i-blog.csdnimg.cn/blog_migrate/3a040979a7f1de19c9abacf5598834b5.jpeg)
可看到刚才下载的两个文件吧.我是在本机上测试的,所以这里在是root目录下的内容.
![](https://i-blog.csdnimg.cn/blog_migrate/56c4de206f07280d251a4ea71bcaa0af.jpeg)
可看到不允许匿名帐号上传文件,正验证了配置文件的正确性
![](https://i-blog.csdnimg.cn/blog_migrate/5f7f762753d29e38338122e1175f3b71.jpeg)
也不允许匿名帐号建立文件目录.
![](https://i-blog.csdnimg.cn/blog_migrate/746a9b5800858385eb7af6868aaff36f.jpeg)
可看到用用户列表里的用户登录,是不成功的.
![](https://i-blog.csdnimg.cn/blog_migrate/177b694049a481929f83e9bd4eb2623a.jpeg)
现在用本地的帐号yang 登录,可见是登录成功的.
2.配置匿名帐号上传功能
只需要修改下面即可:
![](https://i-blog.csdnimg.cn/blog_migrate/d8a19feae0843e8ec63d7113e3ad7eaf.jpeg)
就是去掉前面的#,其它配置现简单匿名帐号配置是相同的.
注意了,因为上传文件和目录的同时,也就是在FTP服务器的本地目录建立文件和目录,所以必须为上传目录指定写权限.
(1)在/var/ftp中建立一个新目录"ding".
![](https://i-blog.csdnimg.cn/blog_migrate/3123a8fb6fade6c6a350951b8c435611.jpeg)
(2)改变目录"ding"的权限
![](https://i-blog.csdnimg.cn/blog_migrate/848868419d44c0bd80114006134c33a1.jpeg)
因为这里建立的是匿名服务器,所以文件所有者属于"ftp-FTP User",文件组群属于"ftp".
(3)建立相应的上传目录后,重新启动FTP服务器,测试如下:
![](https://i-blog.csdnimg.cn/blog_migrate/7303e552a7411e24baf407aa76638a1e.jpeg)
匿名登录
![](https://i-blog.csdnimg.cn/blog_migrate/140adc302b5588ce50259f2858d38c2d.jpeg)
可看到刚才建立的ding目录
![](https://i-blog.csdnimg.cn/blog_migrate/c42262773165bea0d97102ec377881f3.jpeg)
更改到ding目录,在目录中创建目录yangming,可见创建成功.
![](https://i-blog.csdnimg.cn/blog_migrate/5836a1169a7b01b1b960591a90e57e4a.jpeg)
现在上传文件到目录ding中,可看到上传成功.
![](https://i-blog.csdnimg.cn/blog_migrate/84e78eb36d6640051f56476e2282d874.jpeg)
现在来上传文件到目录ftp中,可见失败.因为匿名帐号对目录ftp没有写权限,我们没有设置.
![](https://i-blog.csdnimg.cn/blog_migrate/1fe07180c6c36435a5ab76930dd02ae4.jpeg)
现在切换现创建的yangmin目录下,一开始是不能打开,原因也是没有写权限,
![](https://i-blog.csdnimg.cn/blog_migrate/13c9aa726358ef9fe23a44f18669a201.jpeg)
然后设置写权限就可看到查看成功.即755
![](https://i-blog.csdnimg.cn/blog_migrate/2f243331a2910d0ab96342703b9b80c7.jpeg)
可看到上传文件成功
3.设置连接服务器的最在并发连接数和用户的最在线程数.
作为FTP服务器,必然要为众多用户担任服务,如果在同一时段登录FTP服务器的用户过多或下载数据过量,则会影响服务器的性能,因此,在建立FTP服务器时,一定要设置连接服务器的最大并发用户数和每一用户并发下载文件的最在线程数.修改配置文件/etc/vsftpd/vsftpd.conf添加如下语句
![](https://i-blog.csdnimg.cn/blog_migrate/a12cb3c8aef948b76359db569b6f9bb8.jpeg)
看最后两句,并发用户为100.线程数为2,即同时只能下载两个文件.
4.设置匿名用户的最大传输速率
下载速率对FTP服务器的性能影响也很大,限制用户的最大传输速率可以平均分配网络带宽,增强网络的流畅性,避免网络阻塞.可在配置文件/etc/vsftpd/vsftpd.conf中,添加如下语句:
![](https://i-blog.csdnimg.cn/blog_migrate/246d295e51f408e7b252a5caac54f7da.jpeg)
看最后两行,设置匿名用户的最在传输速率为20Kbps,为本地用户的最大传输速率为1Mbps
5.禁止某些IP段的匿名用户访问FTP服务器.
有些时候,FTP服务器不想对某些主机开放,但它们又处在同一个网络或VLAN中,这时可以限制某些主机访问FTP服务器.方法看下面:
(1)确认配置文件/etc/vsftpd/vsftpd.conf中有如下语句:
![](https://i-blog.csdnimg.cn/blog_migrate/70524caac60290325102a8184866780b.jpeg)
即最后一句
(2)修改文件/etc/hosts.allow如下
![](https://i-blog.csdnimg.cn/blog_migrate/b7418ed9ec0d6c9ae5fbdf66c46305b6.jpeg)
限制IP地址为192.168.0.5的主机访问FTP服务器.
(5)下面进行测试
![](https://i-blog.csdnimg.cn/blog_migrate/ba6b558fcf5838c26701bb599eee777c.jpeg)
可看到可以PING通服务器,但是登录时被拒绝了.
(6)只允许匿名用户访问
如果只允许匿名帐号访问FTP服务器,那么就要限制本地帐号访问.可以修改配置文件/etc/vsftpd/vsftpd.conf , 把下面两行语句注释掉即可:
![](https://i-blog.csdnimg.cn/blog_migrate/1bcaf632caf1319c86760007b0af005f.jpeg)
测试如下:
![](https://i-blog.csdnimg.cn/blog_migrate/53b33b2403dd8105a7657b1a189a48f4.jpeg)
可看到匿名登录成功
![](https://i-blog.csdnimg.cn/blog_migrate/baa2bdee9ca758a1eb82ccef4e827a2f.jpeg)
用本地帐号登录失败,也可看到错误信息,只允许匿名登录.
![](https://i-blog.csdnimg.cn/blog_migrate/b7d5dcebb8d4152dc4046388f0a954f8.jpeg)
列表内的帐号也禁止登录了.
7.设置用ASCII方式传送数据
一般情况下,利用FTP服务器传输数据的时候都是使用ASCII传输方式,所以,有必要对FTP服务器传输数据的格式进行设定.同样修改配置文件/etc/vsftpd/vsftpd.conf.
![](https://i-blog.csdnimg.cn/blog_migrate/5c86151d82ae983923f6787214781fa4.jpeg)
8.设置各种欢迎信息.
设置访问FTP服务器的欢迎信息,可以让用户访问FTP服务器时感到很亲切.同样配置文件/etc/vsftpd/vsftpd.conf.
![](https://i-blog.csdnimg.cn/blog_migrate/ed087218f7760b0089eb2a17e3bd9ca8.jpeg)
测试如下:
![](https://i-blog.csdnimg.cn/blog_migrate/3b76646edb0299e30c0d45e721e9d8dc.jpeg)
可以看到登录的信息了吧.
9.设置数据传输中断的时间间隔
如果用户和FTP服务器之间已经停止了数据的传输,而用户却一直连线在FTP服务器,则会占用网络带宽和FTP服务器的最大用户数限制等资源.修改,配置文件/etc/vsftpd/vsftpd.conf.
![](https://i-blog.csdnimg.cn/blog_migrate/ca53097b202260726c1f83309d43fc56.jpeg)
2.真实帐号服务器
1)用户列表内的用户不能访问FTP服务器.而其它不在列表内的用户可以访问.修改配置文件/etc/vsftpd/vsftpd.conf.
![](https://i-blog.csdnimg.cn/blog_migrate/5f3cbdecd5fd8264d80febaf8368ee19.jpeg)
同时把不允许访问FTP服务器的用户帐号加入到vsftpd.user_list文件中.
![](https://i-blog.csdnimg.cn/blog_migrate/a1c315ebb7cff0618b5df3ad4d1649a8.jpeg)
这里把pudding加进去.
测试结果如下:
![](https://i-blog.csdnimg.cn/blog_migrate/49cd7a6749e41e110e532a86673855ce.jpeg)
root帐号不允许访问
![](https://i-blog.csdnimg.cn/blog_migrate/7c78be4aca5ee04126129648f586b78e.jpeg)
pudding也不允许访问.可见配置成功
![](https://i-blog.csdnimg.cn/blog_migrate/fe8f3145a8b32f32383f94a38bdfb37b.jpeg)
用本机上的另一个帐户就可以访问了.
(2)更改FTP服务器默认的端口号
一般情况下,FTP服务器默认的端口号是21,所有的用户在登录FTP服务器时都需要输入服务器默认的端口号,但是,有时候出于安全的考虑,有必要为FTP服务器指定特定的端口号,在一定程度上增大******服务器的难度.
在配置文件/etc/vsftpd/vsftpd.conf.中添加如下语句:
![](https://i-blog.csdnimg.cn/blog_migrate/8be3ff8955d48ff21771c89a94527b32.jpeg)
测试结果如下:
![](https://i-blog.csdnimg.cn/blog_migrate/28842ea15394ca6a1d564717483a4031.jpeg)
可见没有填写端口号时访问失败.
![](https://i-blog.csdnimg.cn/blog_migrate/f7ccca6feb612e5acdf99a75c3f44a71.jpeg)
填写端口号就访问成功了.
(3)设置组方式访问FTP服务器
为了设置不同的安全级别和管理方便,有时候可以采用用户组群方式访问FTP服务器,这样可以设置不同用户对同一个目录具有不同的访问权限.例如组建test有3个用户test1,test2和test3,要求用户test1对目录/home/test 具有读,写和执行权限(即浏览,下载,上传和建立目录和文件的权限),用户test2和test3对目录/home/test 只具有读和执行权即浏览和下载权限)
1)使用图形化方式建立目录/home/test
![](https://i-blog.csdnimg.cn/blog_migrate/b4804dc39df0258922de1fea934a0340.jpeg)
建立用户,同样建立test2,test3, 并且去掉默认的勾.
![](https://i-blog.csdnimg.cn/blog_migrate/3dfbdae40dba11026779c71e69ed7192.jpeg)
可看到建立好了3个用户.
![](https://i-blog.csdnimg.cn/blog_migrate/e01b0bbc7d660fa6b936f270983d07b6.jpeg)
在主目录里输入如图路径.
其它两个用户也一样.
![](https://i-blog.csdnimg.cn/blog_migrate/f57a5c3d29ae7c76c645bc63a9aa7ca2.jpeg)
并把用户加入组test,这是在之前就已经建立好的组.其它两个用户同样操作.
![](https://i-blog.csdnimg.cn/blog_migrate/cfd570db664ae794ad0c67d6c42ee133.jpeg)
可看下三个用户.
3)设置目录/home/test的所有者和权限.
![](https://i-blog.csdnimg.cn/blog_migrate/9052affea29c585d920969e2333970fc.jpeg)
这样便可以了.即满足了各用户访问的权限.test1读写执行都有,test2,test3对目录有读执行权限.
下面进行测试
![](https://i-blog.csdnimg.cn/blog_migrate/aaaa52fc57e8448bb7afd741473d27ad.jpeg)
用test1登录成功.
![](https://i-blog.csdnimg.cn/blog_migrate/09803aec1c4246be435b273a902cf4af.jpeg)
显示test目录的内容,目前是空的,然后创建目录,成功
![](https://i-blog.csdnimg.cn/blog_migrate/b4f12e9a656333094d4ebbb0f0fa9aab.jpeg)
上传文件到目录test中,成功.
![](https://i-blog.csdnimg.cn/blog_migrate/59860a685ed48551720e96db433898e0.jpeg)
用户test2登录.
![](https://i-blog.csdnimg.cn/blog_migrate/0afb5c2eea2beb38e0022aae1789c6de.jpeg)
创建目录失败,上传文件也失败.
4)限制用户访问的目录.
默认情况下,用户登录到FTP服务器,可以访问服务器中自己目录外的文件,为了增加安全性.有必要进行对用户访问目录的限制.在配置文件/etc/vsftpd/vsftpd.conf中添加下面的语句.
![](https://i-blog.csdnimg.cn/blog_migrate/3c17060d4931fac876c7fe0e46fa1883.jpeg)
下面进行测试
![](https://i-blog.csdnimg.cn/blog_migrate/b6f6d7cbe6979719e8d1b90c038ebd99.jpeg)
登录成功,查看本地目录显示正常.
![](https://i-blog.csdnimg.cn/blog_migrate/e4e8df7002305736da7d9fc8a7ce62a5.jpeg)
目录更改成功,但显示的却还是yang目录下的文件,并不是根下的目录.
OK,到这里有关FTP的全部介绍完毕.
转载于:https://blog.51cto.com/ming228/112083