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
先使用命令查看是否安装.
![](http://blog.51cto.com/attachment/200811/200811111226402003656.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到安装了版本为2.0.1.如果没有安装可在桌面上选择"应用程序"/"系统设置"添加/删除应用程序"命令.来安装FTP软件包.
安装和配置好vsftpd软件包后,需要启动FTP服务器才能使用.启动方法有以下两种:
1.使用图形化方式启动,选择"应用程序"/系统设置/服务器设置/服务.可看到vsftpd,打上勾,开始启动.
2.在终端窗口用命令进行启动.
![](http://blog.51cto.com/attachment/200811/200811111226402299656.jpg?x-oss-process=image/resize,w_1400/format,webp)
还可以使用service命令.
![](http://blog.51cto.com/attachment/200811/200811111226402325546.jpg?x-oss-process=image/resize,w_1400/format,webp)
二.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如下:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404275109.jpg?x-oss-process=image/resize,w_1400/format,webp)
设置允许anonymous登录FTP服务器,允许本地帐号登录,允许本地帐号有写权限.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404343625.jpg?x-oss-process=image/resize,w_1400/format,webp)
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404362875.jpg?x-oss-process=image/resize,w_1400/format,webp)
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404422812.jpg?x-oss-process=image/resize,w_1400/format,webp)
用户列表里的用户不允许登录FTP服务器.
配置好后,需要重新启动vsftpd
匿名帐号可以是ftp或anonymous,口令一个E-Mail地址.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404527531.jpg?x-oss-process=image/resize,w_1400/format,webp)
这里可看到有个默认的FTP目录.
下面进行测试
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404703343.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到匿名帐号输入错误时是不能登录的.输入一个电子邮件地址作为密码也是不能登录.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404856609.jpg?x-oss-process=image/resize,w_1400/format,webp)
更改用户名,然后输入一个电子邮件地址作为密码.,登录成功.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404901062.jpg?x-oss-process=image/resize,w_1400/format,webp)
查看一下FTP帐号在FTP服务器上的目录,然后退出登录.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226404961703.jpg?x-oss-process=image/resize,w_1400/format,webp)
用匿名帐号登录,并输入一个电子邮件地址作为密码.登录成功.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405014453.jpg?x-oss-process=image/resize,w_1400/format,webp)
列出匿名帐号在FTP服务器上的目录,然后更改到pub目录下.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405141125.jpg?x-oss-process=image/resize,w_1400/format,webp)
这是pud目录下的内容.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405215375.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到匿名帐号可以下载文件.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405243468.jpg?x-oss-process=image/resize,w_1400/format,webp)
同样可以下载
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405269562.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到刚才下载的两个文件吧.我是在本机上测试的,所以这里在是root目录下的内容.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405319812.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到不允许匿名帐号上传文件,正验证了配置文件的正确性
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405366875.jpg?x-oss-process=image/resize,w_1400/format,webp)
也不允许匿名帐号建立文件目录.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405399281.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到用用户列表里的用户登录,是不成功的.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405446343.jpg?x-oss-process=image/resize,w_1400/format,webp)
现在用本地的帐号yang 登录,可见是登录成功的.
2.配置匿名帐号上传功能
只需要修改下面即可:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226405884203.jpg?x-oss-process=image/resize,w_1400/format,webp)
就是去掉前面的#,其它配置现简单匿名帐号配置是相同的.
注意了,因为上传文件和目录的同时,也就是在FTP服务器的本地目录建立文件和目录,所以必须为上传目录指定写权限.
(1)在/var/ftp中建立一个新目录"ding".
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406017765.jpg?x-oss-process=image/resize,w_1400/format,webp)
(2)改变目录"ding"的权限
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406080312.jpg?x-oss-process=image/resize,w_1400/format,webp)
因为这里建立的是匿名服务器,所以文件所有者属于"ftp-FTP User",文件组群属于"ftp".
(3)建立相应的上传目录后,重新启动FTP服务器,测试如下:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406231437.jpg?x-oss-process=image/resize,w_1400/format,webp)
匿名登录
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406253875.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到刚才建立的ding目录
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406278000.jpg?x-oss-process=image/resize,w_1400/format,webp)
更改到ding目录,在目录中创建目录yangming,可见创建成功.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406339125.jpg?x-oss-process=image/resize,w_1400/format,webp)
现在上传文件到目录ding中,可看到上传成功.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406384187.jpg?x-oss-process=image/resize,w_1400/format,webp)
现在来上传文件到目录ftp中,可见失败.因为匿名帐号对目录ftp没有写权限,我们没有设置.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406467531.jpg?x-oss-process=image/resize,w_1400/format,webp)
现在切换现创建的yangmin目录下,一开始是不能打开,原因也是没有写权限,
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406724656.jpg?x-oss-process=image/resize,w_1400/format,webp)
然后设置写权限就可看到查看成功.即755
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406609046.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到上传文件成功
3.设置连接服务器的最在并发连接数和用户的最在线程数.
作为FTP服务器,必然要为众多用户担任服务,如果在同一时段登录FTP服务器的用户过多或下载数据过量,则会影响服务器的性能,因此,在建立FTP服务器时,一定要设置连接服务器的最大并发用户数和每一用户并发下载文件的最在线程数.修改配置文件/etc/vsftpd/vsftpd.conf添加如下语句
![](http://ming228.blog.51cto.com/attachment/200811/200811111226406901843.jpg?x-oss-process=image/resize,w_1400/format,webp)
看最后两句,并发用户为100.线程数为2,即同时只能下载两个文件.
4.设置匿名用户的最大传输速率
下载速率对FTP服务器的性能影响也很大,限制用户的最大传输速率可以平均分配网络带宽,增强网络的流畅性,避免网络阻塞.可在配置文件/etc/vsftpd/vsftpd.conf中,添加如下语句:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407080187.jpg?x-oss-process=image/resize,w_1400/format,webp)
看最后两行,设置匿名用户的最在传输速率为20Kbps,为本地用户的最大传输速率为1Mbps
5.禁止某些IP段的匿名用户访问FTP服务器.
有些时候,FTP服务器不想对某些主机开放,但它们又处在同一个网络或VLAN中,这时可以限制某些主机访问FTP服务器.方法看下面:
(1)确认配置文件/etc/vsftpd/vsftpd.conf中有如下语句:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407253203.jpg?x-oss-process=image/resize,w_1400/format,webp)
即最后一句
(2)修改文件/etc/hosts.allow如下
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407294531.jpg?x-oss-process=image/resize,w_1400/format,webp)
限制IP地址为192.168.0.5的主机访问FTP服务器.
(5)下面进行测试
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407385078.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到可以PING通服务器,但是登录时被拒绝了.
(6)只允许匿名用户访问
如果只允许匿名帐号访问FTP服务器,那么就要限制本地帐号访问.可以修改配置文件/etc/vsftpd/vsftpd.conf , 把下面两行语句注释掉即可:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407556031.jpg?x-oss-process=image/resize,w_1400/format,webp)
测试如下:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407600703.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到匿名登录成功
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407652906.jpg?x-oss-process=image/resize,w_1400/format,webp)
用本地帐号登录失败,也可看到错误信息,只允许匿名登录.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407705562.jpg?x-oss-process=image/resize,w_1400/format,webp)
列表内的帐号也禁止登录了.
7.设置用ASCII方式传送数据
一般情况下,利用FTP服务器传输数据的时候都是使用ASCII传输方式,所以,有必要对FTP服务器传输数据的格式进行设定.同样修改配置文件/etc/vsftpd/vsftpd.conf.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407823546.jpg?x-oss-process=image/resize,w_1400/format,webp)
8.设置各种欢迎信息.
设置访问FTP服务器的欢迎信息,可以让用户访问FTP服务器时感到很亲切.同样配置文件/etc/vsftpd/vsftpd.conf.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407905468.jpg?x-oss-process=image/resize,w_1400/format,webp)
测试如下:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226407922921.jpg?x-oss-process=image/resize,w_1400/format,webp)
可以看到登录的信息了吧.
9.设置数据传输中断的时间间隔
如果用户和FTP服务器之间已经停止了数据的传输,而用户却一直连线在FTP服务器,则会占用网络带宽和FTP服务器的最大用户数限制等资源.修改,配置文件/etc/vsftpd/vsftpd.conf.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408128171.jpg?x-oss-process=image/resize,w_1400/format,webp)
2.真实帐号服务器
1)用户列表内的用户不能访问FTP服务器.而其它不在列表内的用户可以访问.修改配置文件/etc/vsftpd/vsftpd.conf.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408368109.jpg?x-oss-process=image/resize,w_1400/format,webp)
同时把不允许访问FTP服务器的用户帐号加入到vsftpd.user_list文件中.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408414546.jpg?x-oss-process=image/resize,w_1400/format,webp)
这里把pudding加进去.
测试结果如下:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408468578.jpg?x-oss-process=image/resize,w_1400/format,webp)
root帐号不允许访问
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408495484.jpg?x-oss-process=image/resize,w_1400/format,webp)
pudding也不允许访问.可见配置成功
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408523796.jpg?x-oss-process=image/resize,w_1400/format,webp)
用本机上的另一个帐户就可以访问了.
(2)更改FTP服务器默认的端口号
一般情况下,FTP服务器默认的端口号是21,所有的用户在登录FTP服务器时都需要输入服务器默认的端口号,但是,有时候出于安全的考虑,有必要为FTP服务器指定特定的端口号,在一定程度上增大黑客攻击服务器的难度.
在配置文件/etc/vsftpd/vsftpd.conf.中添加如下语句:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408691625.jpg?x-oss-process=image/resize,w_1400/format,webp)
测试结果如下:
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408714062.jpg?x-oss-process=image/resize,w_1400/format,webp)
可见没有填写端口号时访问失败.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226408750671.jpg?x-oss-process=image/resize,w_1400/format,webp)
填写端口号就访问成功了.
(3)设置组方式访问FTP服务器
为了设置不同的安全级别和管理方便,有时候可以采用用户组群方式访问FTP服务器,这样可以设置不同用户对同一个目录具有不同的访问权限.例如组建test有3个用户test1,test2和test3,要求用户test1对目录/home/test 具有读,写和执行权限(即浏览,下载,上传和建立目录和文件的权限),用户test2和test3对目录/home/test 只具有读和执行权即浏览和下载权限)
1)使用图形化方式建立目录/home/test
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409114156.jpg?x-oss-process=image/resize,w_1400/format,webp)
建立用户,同样建立test2,test3, 并且去掉默认的勾.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409176312.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看到建立好了3个用户.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409293750.jpg?x-oss-process=image/resize,w_1400/format,webp)
在主目录里输入如图路径.
其它两个用户也一样.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409349968.jpg?x-oss-process=image/resize,w_1400/format,webp)
并把用户加入组test,这是在之前就已经建立好的组.其它两个用户同样操作.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409425468.jpg?x-oss-process=image/resize,w_1400/format,webp)
可看下三个用户.
3)设置目录/home/test的所有者和权限.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409506156.jpg?x-oss-process=image/resize,w_1400/format,webp)
这样便可以了.即满足了各用户访问的权限.test1读写执行都有,test2,test3对目录有读执行权限.
下面进行测试
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409644703.jpg?x-oss-process=image/resize,w_1400/format,webp)
用test1登录成功.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409670328.jpg?x-oss-process=image/resize,w_1400/format,webp)
显示test目录的内容,目前是空的,然后创建目录,成功
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409728984.jpg?x-oss-process=image/resize,w_1400/format,webp)
上传文件到目录test中,成功.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409775375.jpg?x-oss-process=image/resize,w_1400/format,webp)
用户test2登录.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409817140.jpg?x-oss-process=image/resize,w_1400/format,webp)
创建目录失败,上传文件也失败.
4)限制用户访问的目录.
默认情况下,用户登录到FTP服务器,可以访问服务器中自己目录外的文件,为了增加安全性.有必要进行对用户访问目录的限制.在配置文件/etc/vsftpd/vsftpd.conf中添加下面的语句.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409947890.jpg?x-oss-process=image/resize,w_1400/format,webp)
下面进行测试
![](http://ming228.blog.51cto.com/attachment/200811/200811111226409973640.jpg?x-oss-process=image/resize,w_1400/format,webp)
登录成功,查看本地目录显示正常.
![](http://ming228.blog.51cto.com/attachment/200811/200811111226410053703.jpg?x-oss-process=image/resize,w_1400/format,webp)
目录更改成功,但显示的却还是yang目录下的文件,并不是根下的目录.
OK,到这里有关FTP的全部介绍完毕.
本文转自yangming1052 51CTO博客,原文链接:http://blog.51cto.com/ming228/112083
,如需转载请自行联系原作者