设为首页 收藏本站
查看: 1245|回复: 0

[经验分享] debian下ftp服务器配置实例

[复制链接]

尚未签到

发表于 2015-11-6 07:21:03 | 显示全部楼层 |阅读模式
1           服务控制
Ø  通过/etc/init.d下面的vsftpd脚本控制
Ø  启动:/etc/init.d# ./vsftpd start

#service vsftpd start
如果允许用户匿名访问,需创建用户ftp和目录/var/ftp
# mkdir /var/ftp
# useradd –d /var/ftp ftp

Ø  停止:/etc/init.d# ./vsftpd stop
Ø  重启:/etc/init.d# ./vsftpd restart
2           配置相关文件
Ø  /etc/ftpusers  禁止登陆FTP帐户
Ø  /etc/vsftpd.conf
Ø  /etc/vsftpd.user_list 允许登陆FTP帐户(userlist_enable = NO)禁止登陆FTP帐户(userlist_enable = YES
Ø  /etc/vsftpd.chroot_list
Ø  /etc/vsftpd.banned_emails 黑名单电子邮件保存文件
Ø  /etc/hosts.allow 增加ALL:192.168.10.只有指定IP段的用户才能访问FTP服务器。
3           /etc/vsftpd.conf配置项
# 允许匿名用户登陆
anonymous_enable = YES
# 匿名用户登陆时不需要密码
no_anon_password = YES
# 允许本地用户登陆
local_enable = YES
# 允许创建文件保存匿名电子邮件黑名单
deny_email_enable = YES
# 保存匿名电子邮件黑名单的路径
banned_email_file = /etc/vsftpd.banned_emails

# 全局上传权限
write_enable = YES
# 本地用户上穿文件权限掩码022755
local_umask = 022
# 匿名用户上穿权限,需要开放全局上穿权限,同时需要建立匿名用户能够读写的目录。
anon_upload_enable = YES
# 允许匿名用户有创建目录的权限
anon_mkdir_write_enable = YES
# 指定匿名上传得用户名
chown_uploads = YES
chown_username = 用户名
# 限定本地用户只能在自己目录下活动,指定文件中保存受限制的用户

    #将所有本地用户限制在家目录中
chroot_list_enable = YES
chroot_list_file = /etc/vsftpd.chroot_list
# 安全用户帐户
nopriv_user = ftpsecure用户名
#  async_abor_enable = NO
# 启用ascii模式
ascii_upload_enable = YES
ascii_download_enable = YES
# 用户连接和超时选项
idle_session_timeout = 600 空闲时间超过该值时,被踢出服务器。
data_connection_timeout = 120 数据连接超时时间

    accept_timeout=numerical value
   #接受建立联机的超时设定。默认值为60s

# 服务器日志和欢迎信息
dirmessage_enable = YES 允许为目录配置显示信息
ftpd_banner = welcome to blash ftp server
xferlog_enable = YES 启动日志记录功能
xferlog_file =/var/log/vsftpd.log
# 限定访问地址
listen_address=192.168.10.1  只有通过该地址(服务器地址)可以访问。
    listen_port=21#设置ftp监听端口


    #设置虚拟帐号的主目录
    user_config_dir=/etc/vsftpd/vsftpd_user_conf
   
4  配置文件分类解释:


Vsftpd的配置文件存放在/etc/vsftpd/vsftpd.conf  我们可根据实际数要对如下信息进行配置:
1. 连接选项
监听地址和控制端口
(1) listen_address=ip address
定义主机在哪个IP 地址上监听FTP请求。即在哪个IP地址上提供FTP服务。

(2) listen_port=port_value
指定FTP服务器监听的端口号。默认值为21

2. 性能与负载控制
超时选项
(1) idle_session_timeout=
空闲用户会话的超时时间,若是超过这段时间没有数据的传送或是指令的输入,则会被迫断线。默认值是300s

(2) accept_timeout=numerical value
接受建立联机的超时设定。默认值为60s

负载选项
(1) max_clients= numerical value
定义FTP服务器最大的兵法连接数。当超过此连接数时,服务器拒绝客户端连接。默认值为0,表示不限最大连接数。

(2) max_per_ip= numerical value
定义每个IP地址最大的并发连接数目。超过这个数目将会拒绝连接。此选项的设置将会影响到网际快车、迅雷之类的多线程下载软件。默认值为0,表示不限制。

(3) anon_max_rate=value
设定匿名用户的最大数据传输速度,以B/s为单位。默认无。

(4) local_max_rate=value
设定用户的最大数据传输速度。以B/s为单位。默认无。此选项对所有的用户都生效。

3. 用户选项
vsftpd的用户分为3类:匿名用户、本地用户(local user)及虚拟用户(guest
匿名用户
(1) anonymous_enable=YES|NO
控制是否允许匿名用户登录

(2) ftp_username=
匿名用户使用的系统用户名。默认情况下,值为ftp

(3) no_anon_password= YES|NO
控制匿名用户登录时是否需要密码。

(4) anon_root=
设定匿名用户的根目录,即匿名用户登录后,被定位到此目录下。主配置文件中默认无此项,默认值为/var/ftp/

(5) anon_world_readable_only= YES|NO
控制是否只允许匿名用户下载可阅读的文档。YES,只允许匿名用户下载可阅读的文件。NO,允许匿名用户浏览整个服务器的文件系统。

(6) anon_upload_enable= YES|NO
控制是否允许匿名用户上传文件。除了这个参数外,匿名用户要能上传文件,还需要两个条件,write_enable参数为YES;在文件系统上,FTP匿名用户对某个目录有写权限。

(7) anon_mkdir_wirte_enable= YES|NO
控制是否允许匿名用户创建新目录。在文件系统上,FTP匿名用户必须对新目录的上层目录拥有写权限。

(8) anon_other_write_enbale= YES|NO
控制匿名用户是否拥有除了上传和新建目录之外的其他权限。如删除、更名等。

(9) chown_uploads= YES|NO
是否修改匿名用户所上传文件的所有权。YES,匿名用户上传得文件所有权改为另一个不同的用户所有,用户由chown_username参数指定。

(10) chown_username=whoever
指定拥有匿名用户上传文件所有权的用户。

本地用户
(1) local_enable= YES|NO
控制vsftpd所在的系统的用户是否可以登录vsftpd

(2) local_root=
定义本地用户的根目录。当本地用户登录时,将被更换到此目录下。

虚拟用户
(1) guest_enable= YES|NO
启动此功能将所有匿名登入者都视为guest

(2) guest_username=
定义vsftpdguest用户在系统中的用户名。

4. 安全措施
用户登录控制
(1) /etc/vsftpd.ftpusers
Vsftpd禁止列在此文件中的用户登录FTP服务器。此机制是默认设置的。

(2) userlist_enable= YES|NO
此选项激活后,vsftpd将读取userlist_file参数所指定的文件中的用户列表。

(3) userlist_file=/etc/vsftpd.user_list
指出userlist_enable选项生效后,被读取的包含用户列表的文件。默认值是/etc/vsftpd.user_list

(4) userlist_deny= YES|NO
决定禁止还是只允许由userlist_file指定文件中的用户登录FTP服务器。userlist_enable选项启动后才能生效。默认值为YES,禁止文中的用户登录,同时不向这些用户发出输入口令的指令。NO,只允许在文中的用户登录FTP服务器。

目录访问控制
(1) chroot_list_enable= YES|NO
锁定某些用户在自己的目录中,而不可以转到系统的其他目录。

(2) chroot_list_file=/etc/vsftpd/chroot_list
指定被锁定在主目录的用户的列表文件。

(3) chroot_local_users= YES|NO
将本地用户锁定在主目中。





5。虚拟机配置FTP遇到的问题:
# Example config file /etc/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.
#
#
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=YES
# listen_address=192.168.2.126
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.
#listen_ipv6=YES
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
no_anon_password=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# 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
#
# 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
#
# 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
#
# 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
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# 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
#
# 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 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_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# 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 restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# 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
# (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
#
#
# Debian customization
#
# Some of vsftpd's settings don't fit the Debian filesystem layout by
# default.  These settings are more Debian-friendly.
#
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/vsftpd.pem

vsftpd程序不能启动;
现象:先进入目录/etc/init.d#./vsftpd start命令启动,之后用ps -ef并未发现该任务启动
然后直接启动/usr/sbin/vsftpd,报错500 OOPS: could not bind listening IPv4 socket;之前在/etc/vsftpd.conf中增加了一行:listen_address=192.168.2.100;该ip为客户端ip造成了如上的错误;更改为本机IP192.168.2.126后,在本机上能够正常登陆,但是还是不能从其它机器上登陆,原来是其它机器的2021端口号没有开放,开放后能够正常登陆。
    但是匿名用户还是不能登陆,总是要求输入密码,但是之前在配置文件中增加了一行:no_anon_password=YES不知道为什么不起作用。
    将上述添加的两行去掉以后,依然是匿名用户不能登陆。怀疑是匿名用户被设置了密码。
root用户下,使用passwd ftp设置了ftp匿名用户ftp的密码为ftp,这时可以匿名登陆成功,但是成功后只能显示一个空目录。看上面的配置文件应该是需要创建FTP读写权限的文件目录,这个没有测试,有兴趣的可以测试下,记得把测试结果告诉我啊,嘿嘿。

6./etc/ftpusers中的root用户注释后,重新启动vsftpd后,root能够正常登陆了。

# /etc/ftpusers: list of users disallowed FTP access. See ftpusers(5).
# root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
nobody




附录:转自LinuxSir.Org论坛

FTP 原理
FTP Transfer Protocol 件传输协议的缩写,在RFC 959中具体说明。
FTP会话时包含了两个通道,一个叫控制通道,一个叫数据通道。
控制通道:控制通道是和FTP服务器进行沟通的通道,连接FTP,发送FTP指令都是通过控制通道来完成的。
数据通道:数据通道是和FTP服务器进行文件传输或者列表的通道。
FTP协议中,控制连接均有客户端发起,而数据连接有两种工作方式:PORT方式和PASV方式
PORT模式(主动方式)
FTP 客户端首先和FTP Server的TCP 21端口建立连接,通过这个通道发送命令,客户端需要接收数据的时候在这个通道上发送PORT命令。 PORT命令包含了客户端用什么端口(一个大于1024的端口)接收数据。在传送数据的时候,服务器端通过自己的TCP 20端口发送数据。 FTP server必须和客户端建立一个新的连接用来传送数据。
PASV模式(被动方式)
在建立控制通道的时候和PORT模式类似,当客户端通过这个通道发送PASV 命令的时候,FTP server打开一个位于1024和5000之间的随机端口并且通知客户端在这个端口上传送数据的请求,然后FTP server 将通过这个端口进行数据的传送,这个时候FTP server不再需要建立一个新的和客户端之间的连接传送数据。
如果从C/S模型这个角度来说,PORT对于服务器来说是OUTBOUND,而PASV模式对于服务器是INBOUND,这一点请特别注意,尤其是在使用防火墙的企业里,这一点非常关键,如果设置错了,那么客户将无法连接。

  
  
  
  项目中遇到的问题:
  
问题1UltraEdit使用FTP/SFTP浏览器不能登陆到linux服务器。
答:更改配置文件/etc/vsftpd.confasync_abor_enable=YES更改为async_abor_enable=NO
问题2:增加两项后把nari用户访问目录限制在home目录下后,UltraEdit不能浏览目录。
# chroot_list_enable = YES
# chroot_list_file=/etc/vsftpd.chroot_list
把这两项开放后,不能启动vsftpd服务;去掉以后正常启动。
等号两边不能有空格。
  





   
版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-135595-1-1.html 上篇帖子: linux下建ftp用户,并限制用户访问路径 下篇帖子: python实现ftp的基本功能
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表