vsftp 只能下载不能上传,用root用户登陆,然后上传文件也报错,如下:

pressman 2008-10-13 04:52:37
状态:> [2008-10-13 16:47:42] 正在连接 FTP 数据 socket... 61.152.182.249:38614...
[2008-10-13 16:47:42] 550 Access is denied.
错误:> [2008-10-13 16:47:42] 请求的操作未执行(如,文件或目录未找到,不能访问)。

配置文件信息:
# 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
anon_world_readable_only=no
#
# 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 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
#
# 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 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

pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=NO
#enable for standalone mode
listen=YES
tcp_wrappers=YES
userlist_file=/etc/vsftpd.user_list
...全文
716 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bshawk 2008-10-13
  • 打赏
  • 举报
回复
如果暂不考虑安全性,试试如下修改:
1.添加如下配置
anon_other_write_enable=YES

2.修改你ftp server 目录权限

chmod 777 /your_ftp_servr_dir/

formatfocx 2008-10-13
  • 打赏
  • 举报
回复
试下,保证好用

三、三种方式的实现
1、匿名用户形式实现
# vi builddefs.h \\编辑builddefs.h 文件,文件内容如下:

#ifndef VSF_BUILDDEFS_H

#define VSF_BUILDDEFS_H
#undef VSF_BUILD_TCPWRAPPERS
#define VSF_BUILD_PAM
#undef VSF_BUILD_SSL

#endif /* VSF_BUILDDEFS_H */
将以上undef的都改为define,支持tcp_wrappers,支持PAM认证方式,支持SSL

# make //直接在vsftpd-2.0.3里用make编译
# ls -l vsftpd
-rwxr-xr-x 1 root root 86088 Jun 6 12:29 vsftpd //可执行程序已被编译成功

创建必要的帐号,目录:
# useradd nobody //可能你的系统已经存在此帐号,那就不用建立
# mkdir /usr/share/empty //可能你的系统已经存在此目录,那就不用建立
# mkdir /var/ftp //可能你的系统已经存在此目录,那就不用建立
# useradd -d /var/ftp ftp //可能你的系统已经存在此帐号,那就不用建立
# chown root:root /var/ftp
# chmod og-w /var/ftp
请记住,如果你不想让用户在本地登陆,那么你需要把他的登陆SHELL设置成/sbin/nologin,比如以上的nobody和ftp我就设置成/sbin/nologin

安装vsftp配置文件,可执行程序,man等:
# install -m 755 vsftpd /usr/local/sbin/vsftpd-ano
# install -m 644 vsftpd.8 /usr/share/man/man8
# install -m 644 vsftpd.conf.5 /usr/share/man/man5
# install -m 644 vsftpd.conf /etc/vsftpd-ano.conf
这样就安装完成了,那么我们开始进行简单的配置

# vi /etc/vsftpd-ano.conf ,将如下三行加入文件
listen=YES
listen_port=21
tcp_wrappers=YES
anon_root=/var/ftp //设置匿名用户本地目录,和ftp用户目录必须相同
listen=YES的意思是使用standalone启动vsftpd,而不是super daemon(xinetd)控制它 (vsftpd推荐使用standalone方式)
# /usr/local/sbin/vsftpd-ano /etc/vsftpd-ano.conf & //以后台方式启动vsftpd
注意:每行的值都不要有空格,否则启动时会出现错误,举个例子,假如我在listen=YES后多了个空格,那我启动时就出现如下错误:
500 OOPS: bad bool value in config file for: listen

测试搭建好的匿名用户方式
# ftp 127.0.0.1
Connected to 127.0.0.1.
220 (vsFTPd 2.0.3)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (127.0.0.1:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>; pwd
257 "/"
ftp>; quit
221 Goodbye.
#
OK,已经完成了,very nice.

高级配置
细心的朋友可能已经看出来我们只在默认配置文件增加了四行,就实现了FTP连接(也证明了vsftpd的易用性),那么让我们传个文件吧,呀!!传输失败了(见图1)
为什么呢?因为 vsftpd 是为了安全需要,/var/ftp目录不能把所有的权限打开,所以我们这时要建一个目录pub,当然也还是需要继续修改配置文件的。
# mkdir /var/ftp/pub
# chmod -R 777 /var/ftp/pub

为了测试方便,我们先建立一个名为kill-ano的脚本,是为了杀掉FTP程序的
#!/bin/bash
a=`/bin/ps -A | grep vsftpd-ano | awk '{print $1}'`
kill -9 $a

那么现在大家看看我的匿名服务器配置文件吧
anonymous_enable=YES //允许匿名访问,这是匿名服务器必须的
write_enable=YES //全局配置可写
no_anon_password=YES //匿名用户login时不询问口令
anon_umask=077 //匿名用户上传的文件权限是-rw----
anon_upload_enable=YES //允许匿名用户上传文件
anon_mkdir_write_enable=YES //允许匿名用户建立目录
anon_other_write_enable=YES //允许匿名用户具有建立目录,上传之外的权限,如重命名,删除
dirmessage_enable=YES //当使用者转换目录,则会显示该目录下的.message信息
xferlog_enable=YES //记录使用者所有上传下载信息
xferlog_file=/var/log/vsftpd.log //将上传下载信息记录到/var/log/vsftpd.log中
xferlog_std_format=YES //日志使用标准xferlog格式
idle_session_timeout=600 //客户端超过600S没有动作就自动被服务器踢出
data_connection_timeout=120 //数据传输时超过120S没有动作被服务器踢出
chown_uploads=YES
chown_username=daemon //上传文件的属主
ftpd_banner=Welcome to d-1701.com FTP service. //FTP欢迎信息
anon_max_rate=80000 //这是匿名用户的下载速度为80KBytes/s
check_shell=NO //不检测SHELL

现在再测试,先kill掉再启动FTP程序
# ./kill-ano
# /usr/local/sbin/vsftpd-ano /etc/vsftpd-ano.conf &
上传一个文件测试一下,怎么样?OK了吧,下载刚上传的那个文件,恩?不行,提示
550 Failed to open file.
传输已失败!
传输队列已完成
1 个文件传输失败

没有关系,你记得咱们设置了anon_umask=077了吗?所以你下载不了,如果你到服务器上touch 一个文件(644),测试一下,是可以被下载下来的,好了,匿名服务器就说到这里了。


2、本地用户形式实现
# cd /home/xuchen/vsftpd-2.0.3 //进入vsftpd-2.0.3的源代码目录
# make clean //清除编译环境
# vi builddefs.h \\继续编辑builddefs.h 文件,文件内容如下:
#ifndef VSF_BUILDDEFS_H

#define VSF_BUILDDEFS_H
#define VSF_BUILD_TCPWRAPPERS
#define VSF_BUILD_PAM
#define VSF_BUILD_SSL

#endif /* VSF_BUILDDEFS_H */
将以上define VSF_BUILD_PAM行的define改为undef,支持tcp_wrappers,不支持PAM认证方式,支持SSL,记住啊,如果支持了PAM认证方式,你本地用户是不能登陆的。

# make //直接在vsftpd-2.0.3里用make编译
# ls -l vsftpd
-rwxr-xr-x 1 root root 84712 Jun 6 18:56 vsftpd //可执行程序已被编译成功

创建必要的帐号,目录:
# useradd nobody //可能你的系统已经存在此帐号,那就不用建立
# mkdir /usr/share/empty //可能你的系统已经存在此目录,那就不用建立
# mkdir /var/ftp //可能你的系统已经存在此目录,那就不用建立
# useradd -d /var/ftp ftp //可能你的系统已经存在此帐号,那就不用建立
# chown root:root /var/ftp
# chmod og-w /var/ftp
请记住,如果你不想让用户在本地登陆,那么你需要把他的登陆SHELL设置成/sbin/nologin,比如以上的nobody和ftp我就设置成/sbin/nologin

安装vsftp配置文件,可执行程序,man等:
# install -m 755 vsftpd /usr/local/sbin/vsftpd-loc
# install -m 644 vsftpd.8 /usr/share/man/man8
# install -m 644 vsftpd.conf.5 /usr/share/man/man5
# install -m 644 vsftpd.conf /etc/vsftpd-loc.conf
这样就安装完成了,那么我们开始进行简单的配置

# vi /etc/vsftpd-loc.conf ,将如下三行加入文件
listen=YES
listen_port=21
tcp_wrappers=YES //支持tcp_wrappers,限制访问(/etc/hosts.allow,/etc/hosts.deny)
listen=YES的意思是使用standalone启动vsftpd,而不是super daemon(xinetd)控制它 (vsftpd推荐使用standalone方式),注意事项请参看匿名用户的配置。
anonymous_enable=NO
local_enable=YES //这两项配置说不允许匿名用户登陆,允许本地用户登陆
# /usr/local/sbin/vsftpd-loc /etc/vsftpd-loc.conf & //以后台方式启动vsftpd

测试搭建好的匿名用户方式,先测试root用户吧 :)
# ftp 127.0.0.1
Connected to 127.0.0.1.
220 (vsFTPd 2.0.3)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (127.0.0.1:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>; pwd
257 "/root"
ftp>; quit
221 Goodbye.
我们看到root用户可以登陆到ftp,他的登陆目录就是自己的主目录。
再测试一个系统用户,那我们先建立一个用户名叫xuchen的
# useradd xuchen
# passwd xuchen
Changing password for user xuchen.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
建立好了,让我们开始测试吧!!
# ftp 127.0.0.1
Connected to 127.0.0.1.
220 (vsFTPd 2.0.3)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (127.0.0.1:root): xuchen
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>; pwd
257 "/home/xuchen"
ftp>; quit
221 Goodbye.
我们看到xuchen用户可以登陆到ftp,他的登陆目录也是自己的主目录。哈哈,又完成了!
高级配置
细心的朋友可能已经看出来如果我们不支持PAM认证方式,那么本地用户就可以登陆,而默认编译的vsftpd支持PAM认证方式,所以是不支持本地用户登陆的。恩,从这点说,这也是vsftp安全的一个表现----禁止本地用户登陆。
我们登陆后进行测试,传一个文件上去,得,失败了,那下载个文件下来吧,恩,这是成功的(见图2),而且我们发现我们可以进入到系统根目录(见图3),这样很危险。



那么改配置文件吧,为了测试方便,我们先建立一个名为kill-loc的脚本,也是为了杀掉FTP程序的
#!/bin/bash
a=`/bin/ps -A | grep vsftpd-loc | awk '{print $1}'`
kill -9 $a

现在提供我的本地用户验证服务器配置文件吧(在匿名里写过的注释我就不在这里写了)
listen=YES
listen_port=21
tcp_wrappers=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022 //本地用户文件上传后的权限是-rw-r-r
anon_upload_enable=NO
anon_mkdir_write_enable=NO
dirmessage_enable=YES
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
connect_from_port_20=YES
chroot_local_user=YES //限制用户在自己的主目录
#local_root=/ftp //你可以指定所有本地用户登陆后的目录,如果不设置此项,用户都会登陆于自己的主目录,就跟咱们前面测试的结果是一样的
local_max_rate=500000 //本地用户的下载速度为500KBytes/s
idle_session_timeout=600
data_connection_timeout=120
nopriv_user= nobody //设定服务执行者为nobody,vsftpd推荐使用一个权限很低的用户,最好是没有家目录(/dev/null),没有登陆shell(/sbin/nologin),系统会更安全
ftpd_banner=Welcome to d-1701.com FTP service.
check_shell=NO

userlist_enable=YES
userlist_deny=YES
userlist_file=/etc/vsftpd.denyuser
以上三条设定不允许登陆的用户,用户列表存放在/etc/vsftpd.denyuser中,一行一个帐号如果我把xuchen这个用户加到vsftpd.denyuser里,那么登陆时会出现如下错误:
# ftp 127.0.0.1
Connected to 127.0.0.1.
220 Welcome to d-1701.com FTP service.
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (127.0.0.1:root): xuchen
530 Permission denied.
Login failed.
呵呵,有意思吧,自己测试吧,本地用户登陆方式就介绍到这里吧!

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧