您的位置:首页 > 编程语言 > PHP开发

Ubuntu9.10中安装及架设vsftp(ftp)服务器

2010-06-23 16:13 501 查看
1. sudo apt-get install vsftpd

2. 使用 netstat -tnl 可以查看是否打开了 21 端口。

tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN

3. 用浏览器访问一下吧
ftp://10.45.7.25
安装完毕后,匿名用户可以正常访问ftp

=====================================

下面对 ftp 进行一些简单的配置 可以让用户登录 而且可以上传文件

首先修改 vsftpd.conf 配置文件,必须要管理员权限才可以

vi /etc/vsftpd.conf

# 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

#

# 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

#

# 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

#

anon_umask=022

#

# Activate directory messages - messages given to remote users when they

# go into a certain directory.

dirmessage_enable=YES

#

# If enabled, vsftpd will display directory listings with the time

# in your local time zone. The default is to display GMT. The

# times returned by the MDTM FTP command are also affected by this

# option.

use_localtime=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.

# 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

#

# 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_local_user=YES

#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/empty

#

local_root=/srv/ftp

#

# 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/ssl-cert-snakeoil.pem

以上是个人的vsftpd.conf配置文件(注:修改前先备份以防出错,命令sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.old)!

权限配置等:

在/srv/ftp下建立一个目录pub(名字可以随便取,但中文可能有乱码。有些中文编码在windows下可以识别,但在linux下无法识别,郁闷!pub目录是为用户上传和下载文件而创建的)

修改ftp文件夹权限:chmod 755 /srv/ftp

修改pub文件夹权限:chmod 777 /srv/ftp/pub

vsftpd.conf用gedit /etc/vsftpd.conf即可编辑(也可以用vim命令,但要安装vim)。

对了,更改配置后不要忘了重启ftp服务

sudo /etc/init.d/vsftpd restart

此外还有开启关闭服务的命令

sudo /etc/init.d/vsftpd start

sudo /etc/init.d/vsftpd stop

若不是超级用户,在命令前要加sudo哦!红色字体为我个人所修改!这样就可以实现可以上上传和下载文件了(包括匿名用户)。

以下是一个供参考实例(看实例时不要急着试,先看自己的是什么情况):

Vsftp匿名用户不能下载原因分析及解决

近期在群里,坛子里,包括自己做练习的时候都遇到了上面的问题,搜索网络也没找到比较确切的答案;后又查看了大量的相关文章和资料,现把这个问题拿出来分析解决,供广大vsftp学习新人参考:(这个问题和防火墙无关,关闭iptables)

vsftp中的和匿名用户有关的参数:

1)主配置文件:/etc/vsftpd/vsftpd.conf

--------------------------------------------------

[root@station ~]# cat /etc/vsftpd/vsftpd.conf |grep -v ^#

anonymous_enable=YES

local_enable=YES

write_enable=YES

local_umask=022 //本地用户上传文件的umask值。

anon_upload_enable=YES //允许匿名上传

anon_mkdir_write_enable=YES //匿名用户可以对目录进行写操作。

dirmessage_enable=YES

xferlog_enable=YES

connect_from_port_20=YES

xferlog_std_format=YES

listen=YES

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

---------------------------------------------------

2)看相关的selinux设置:

---------------------------------------------------

[root@station ~]# getsebool -a |grep ftp

allow_ftpd_anon_write --> on //匿名用户写权限,要开启

allow_ftpd_full_access --> on //匿名用户要上传文件,要开启

allow_ftpd_use_cifs --> off

allow_ftpd_use_nfs --> off

allow_tftp_anon_write --> off

ftp_home_dir --> on //本地用户家目录

ftpd_disable_trans --> off //关闭selinux对ftp服务的影响

ftpd_is_daemon --> on

httpd_enable_ftp_server --> off

tftpd_disable_trans --> off

------------------------------------------------------

按照上面的设置,重启服务就好了。大多数新人看到的文章基本都是这么配置的,但是我们遇到的问题就产生了。

现象:匿名用户能登陆ftp服务器(linux客户端,或者windows客户端都可以)使用linux客户端,可以上传文件,可以建立目录;使用windows客户端可以长传文件,建立目录不能修改名字,只能用新建文件夹 新建文件夹1......

分析:

1、能确定的一定是权限问题。

2、关闭selinux测试,问题依旧,说明和selinux无关。

3、我们来看一下我们上传的文件:

1)目标目录的权限:

------------------------------------------------------

[root@station booleans]# ll /var/ftp/

总计 16

drwxr-xr-x 2 root root 4096 2007-12-13 pub

drwxrwxrwx 2 root root 4096 09-15 10:25 test //777权限没问题

------------------------------------------------------

2)上传以后的文件的权限:

------------------------------------------------------

lftp 192.168.1.10:/test> put /root/install.log ./

27001 bytes transferred

lftp 192.168.1.10:/test> ls

-rw------- 1 14 50 27001 Sep 15 02:31 install.log

------------------------------------------------------

注意看那个权限600,这是造成我们不能下载的主要原因。

解决方法:

/etc/vsftpd/vsftpd.conf下只有local_umask=022的选项,他决定了上传月以后的文件的权限。默认文件权限是666,目录权限是777,然而我们的匿名用户上传的文件的权限却没有写明,那么默认的vsftp服务对匿名用户的umask值是多少呢?根据我们的测试,应该是066。所以我们要修改匿名用户的umask值使我们可以进行一些相关操作,增加anon_umask=022,重启服务,然后测试vsftp 是不是能下载了?

-----------------------------------------------------

lftp localhost:/test> put /root/install.log

27001 bytes transferred

lftp localhost:/test> ls

-rw-r--r-- 1 14 50 27001 Sep 15 02:34 install.log

-----------------------------------------------------

目录的权限是多少呢?自己测试下,注意资料的安全,设定一个合适的umask值。

本文出自 “努力学习,天天向上” 博客,请务必保留此出处http://iminmin.blog.51cto.com/689308/201607

附:

对了,更改配置后不要忘了重启ftp服务

sudo /etc/init.d/vsftpd restart

此外还有开启关闭服务的命令

sudo /etc/init.d/vsftpd start

sudo /etc/init.d/vsftpd stop

anonymous_enable=yes (允许匿名登陆)

dirmessage_enable=yes (切换目录时,显示目录下.message的内容)

local_umask=022 (FTP上本地的文件权限,默认是077)

connect_form_port_20=yes (启用FTP数据端口的数据连接)*

xferlog_enable=yes (激活上传和下传的日志)

xferlog_std_format=yes (使用标准的日志格式)

ftpd_banner=XXXXX (欢迎信息)

pam_service_name=vsftpd (验证方式)*

listen=yes (独立的VSFTPD服务器)*

功能:只能连接FTP服务器,不能上传和下传

注:其中所有和日志欢迎信息相关连的都是可选项,打了星号的无论什么帐户都要添加,是属于FTP的基本选项

开启匿名FTP服务器上传权限

在配置文件中添加以下的信息即可:

Anon_upload_enable=yes (开放上传权限)

Anon_mkdir_write_enable=yes (可创建目录的同时可以在此目录中上传文件)

Write_enable=yes (开放本地用户写的权限)

Anon_other_write_enable=yes (匿名帐号可以有删除的权限)

开启匿名服务器下传的权限

Anon_world_readable_only=no

注:要注意文件夹的属性,匿名帐户是其它(other)用户要开启它的读写执行的权限

(R)读-----下传 (W)写----上传 (X)执行----如果不开FTP的目录都进不去

Local_enble=yes (本地帐户能够登陆)

Write_enable=no (本地帐户登陆后无权删除和修改文件)

功能:可以用本地帐户登陆vsftpd服务器,有下载上传的权限

注:在禁止匿名登陆的信息后匿名服务器照样可以登陆但不可以上传下传

用户登陆限制进其它的目录,只能进它的主目录

设置所有的本地用户都执行chroot

Chroot_local_user=yes (本地所有帐户都只能在自家目录)

设置指定用户执行chroot

Chroot_list_enable=yes (文件中的名单可以调用)

Chroot_list_file=/任意指定的路径/vsftpd.chroot_list

注意:vsftpd.chroot_list 是没有创建的需要自己添加,要想控制帐号就直接在文件中加帐号即可

限制本地用户访问FTP

Userlist_enable=yes (用userlistlai 来限制用户访问)

Userlist_deny=no (名单中的人不允许访问)

Userlist_file=/指定文件存放的路径/ (文件放置的路径)

注:开启userlist_enable=yes匿名帐号不能登陆

安全选项

Idle_session_timeout=600(秒) (用户会话空闲后10分钟)

Data_connection_timeout=120(秒) (将数据连接空闲2分钟断)

Accept_timeout=60(秒) (将客户端空闲1分钟后断)

Connect_timeout=60(秒) (中断1分钟后又重新连接)

Local_max_rate=50000(bite) (本地用户传输率50K)

Anon_max_rate=30000(bite) (匿名用户传输率30K)

Pasv_min_port=50000 (将客户端的数据连接端口改在

Pasv_max_port=60000 50000—60000之间)

Max_clients=200 (FTP的最大连接数)

Max_per_ip=4 (每IP的最大连接数)

Listen_port=5555 (从5555端口进行数据连接)

查看谁登陆了FTP,并杀死它的进程

ps –xf |grep ftp

kill 进程号

对了,匿名上传文件时,文件右上角有把小锁!而且文件为中文名时,照片和文档是不能在浏览器在直接浏览!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: