因為我打算vsftpd與proftpd共存,proftpd是對外,然後vsftpd是管理人員專用

listen=YES
listen_port=10021
pasv_min_port=30000
pasv_max_port=30999

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

以下是參考資料:

vsftpd-1.1.3配制實例之五
http://www.linuxsir.org/bbs/archive/index.php/t-43449.html

LinuxSir.Org > Linux 综合讨论区 —— LinuxSir.Org > Linux 专业英文精品技术文档专题 > vsftpd-1.1.3配制实例之五:VIRTUAL_USERS
PDA

查看完整版本 : vsftpd-1.1.3配制实例之五:VIRTUAL_USERS
北南南北
03-06-01, 09:28
README


This example shows how to set up vsftpd / PAM with "virtual users".
A virtual user is a user login which does not exist as a real login on the
system. Virtual users can therefore be more secure than real users, beacuse
a compromised account can only use the FTP server.

Virtual users are often used to serve content that should be accessible to
untrusted users, but not generally accessible to the public.

Step 1) Create the virtual users database.
We are going to use pam_userdb to authenticate the virtual users. This needs
a username / password file in "db" format - a common database format.
To create a "db" format file, first create a plain text files with the
usernames and password on alternating lines.
See example file "logins.txt" - this specifies "tom" with password "foo" and
"fred" with password "bar".
Whilst logged in as root, create the actual database file like this:

db_load -T -t hash -f logins.txt /etc/vsftpd_login.db
(Requires the Berkeley db program installed).

This will create /etc/vsftpd_login.db. Obviously, you may want to make sure
the permissions are restricted:

chmod 600 /etc/vsftpd_login.db

For more information on maintaing your login database, look around for
documentation on "Berkeley DB", e.g.
http://www.sleepycat.com/docs/utility/index.html


Step 2) Create a PAM file which uses your new database.

See the example file vsftpd.pam. It contains two lines:

auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd_login

This tells PAM to authenticate users using our new database. Copy this PAM
file to the PAM directory - typically /etc/pam.d/

cp vsftpd.pam /etc/pam.d/ftp


Step 3) Set up the location of the files for the virtual users.

useradd -d /home/ftpsite virtual
ls -ld /home/ftpsite
(which should give):
drwx------ 3 virtual virtual 4096 Jul 30 00:39 /home/ftpsite

We have created a user called "virtual" with a home directory "/home/ftpsite".
Let's add some content to this download area:

cp /etc/hosts /home/ftpsite
chown virtual.virtual /home/ftpsite/hosts


Step 4) Create your vsftpd.conf config file.

See the example in this directory. Let's go through it line by line:

anonymous_enable=NO
local_enable=YES

This disables anonymous FTP for security, and enables non-anonymous FTP (which
is what virtual users use).

write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO

These ensure that for security purposes, no write commands are allowed.

chroot_local_user=YES

This makes sure that the virtual user is restricted to the virtual FTP area
/home/ftpsite we set up above.

guest_enable=YES
guest_username=virtual

The guest_enable is very important - it activates virtual users! And
guest_username says that all virtual users are mapped to the real user
"virtual" that we set up above. This will also determine where on the
filesystem the virtual users end up - the home directory of the user
"virtual", /home/ftpsite.

listen=YES
listen_port=10021

This puts vsftpd in "standalone" mode - i.e. not running from an inetd. This
means you just run the vsftpd executable and it will start up. This also
makes vsftpd listen for FTP requests on the non-standard port of 10021 (FTP
is usually 21).

pasv_min_port=30000
pasv_max_port=30999

These put a port range on passive FTP incoming requests - very useful if
you are configuring a firewall.

Copy the example vsftpd.conf file to /etc:

cp vsftpd.conf /etc/


Step 5) Start up vsftpd.

Go to the directory with the vsftpd binary in it, and:

./vsftpd

If all is well, the command will sit there. If all is not well, you will
likely see some error message.


Step 6) Test.

Launch another shell session (or background vsftpd with CTRL-Z and then "bg").
Here is an example of an FTP session:

ftp localhost 10021
Connected to localhost (127.0.0.1).
220 ready, dude (vsFTPd 1.1.0: beat me, break me)
Name (localhost:chris): tom
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls
227 Entering Passive Mode (127,0,0,1,117,135)
150 Here comes the directory listing.
226 Transfer done (but failed to open directory).
ftp> size hosts
213 147
ftp>

Comments:
The password we gave was "foo".
Do not be alarmed by the "failed to open directory". That is because the
directory /home/ftpsite is not world readable (we could change this
behaviour if we wanted using anon_world_readable_only=NO but maybe we want
it this way for security.
We can see that we have access to the "hosts" file we copied into the virtual
FTP area, via the size command.
北南南北
03-06-01, 09:28
logins.txt

tom
foo
fred
bar
北南南北
03-06-01, 09:30
vsftpd.conf


anonymous_enable=NO
local_enable=YES
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
chroot_local_user=YES
guest_enable=YES
guest_username=virtual
listen=YES
listen_port=10021
pasv_min_port=30000
pasv_max_port=30999
北南南北
03-06-01, 09:30
vsftpd.pam

auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd_login
北南南北
03-06-01, 09:32
VIRTUAL_USERS_2

README


This example shows how to extend the "VIRTUAL_USERS" example to reflect
a slightly more complex setup.

Let's assume that we want two types of virtual user - one that can only browse
and download content, and another that can upload new content as well as
download existing content.

To achieve this setup, we can use use of vsftpd's powerful per-user
configurability (new in v1.1.0).

In the previous virtual user example, we created two users - tom and fred.
Let's say that we want fred to have write access to upload new files whilst
tom can only download.

Step 1) Activate per-user configurability.

To activate this powerful vsftpd feature, add the following to
/etc/vsftpd.conf:
user_config_dir=/etc/vsftpd_user_conf

And, create this directory:

mkdir /etc/vsftpd_user_conf


Step 2) Give tom the ability to read all files / directories.

At the end of the last example, we noted that the virtual users can only
see world-readable files and directories. We could make the /home/ftpsite
directory world readable, and upload files with world-read permission. But
another way of doing this is giving tom the ability to download files which
are not world-readable.

For the tom user, supply a config setting override for
anon_world_readable_only:

echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/tom

Check it out - login as tom and now "ls" will return a directory listing!
Log in as fred and it won't.
NOTE - restart vsftpd to pick up the config setting changes to
/etc/vsftpd.conf. (Advanced users can send SIGHUP to the vsftpd listener
process).


Step 3) Give fred the ability to read all files / directories and create
new ones but not interfere with existing files.

echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/fred
echo "write_enable=YES" >> /etc/vsftpd_user_conf/fred
echo "anon_upload_enable=YES" >> /etc/vsftpd_user_conf/fred

Check it out - login as tom and you can't upload. Log in as fred and you can!
Try and delete a file as both tom and fred - you can't.
freebsdchina
03-06-23, 16:50
#约定: 所有在"[ ]"里的都是应该直接在运行的命令,所有的目录因素已经完整


准备:
1) 确认已经安装vsftpd
[rpm -q vsftpd]

2) 确认安装Berkeley db
[rpm -q db4 ]

开始:

1) 生成虚拟用户的数据库:
使用pam_userdb 来认证虚拟用户.
先生成一个logins.txt:
[vi /root/logins.txt ]

tom
foo
fred
bar

[db_load -T -t hash -f /root/logins.txt /etc/vsftpd/vsftpd_login.db]
[chmod 600 /etc/vsftpd/vsftpd_login.db]

#更多关于DB 的资料,看下面:

http://www.sleepycat.com/docs/utility/index.html


2) 生成一个使用你的新的db的PAM 文件.
[vi /etc/pam.d/vsfptd]
修改成如下:

auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

[cp /etc/pam.d/vsftpd /etc/pam.d/ftp]




3) 建立虚拟用户的目录.

[useradd -d /home/ftpsite virtual ]
[ls -ld /home/ftpsite ]
(看起来应该是这样的):
drwx------ 3 virtual virtual 4096 Jul 30 00:39 /home/ftpsite

拷贝一个文件来做测试用:

[cp /etc/hosts /home/ftpsite]
[chown virtual.virtual /home/ftpsite/hosts]

4) 建立你自己的 /etc/vsftpd/vsftpd.conf 文件



anonymous_enable=NO
local_enable=YES

#这禁止了匿名用户使用FTP 服务,并且允许非匿名用户的登录,就是虚拟用户所需要的权限

write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO

#出于安全的目的,禁止写权限

chroot_local_user=YES

#这明确了虚拟用户是被定向到了虚拟的FTP 空间:/home/ftpsite


guest_enable=YES
guest_username=virtual

# guest_enable 是很重要的- 它激活了虚拟用户的选项! 而guest_username 说明所有的虚拟用户被看做是实际的用户"virtual" . 这也帮助确定用户的目录.

listen=YES
listen_port=10021

# 使 vsftpd 以"standalone" 模式运行- 端口10021

pasv_min_port=30000
pasv_max_port=30999

#限定端口,方便防火墙的设置

5) 运行 vsftpd.
[vsftpd /etc/vsftpd/vsftpd.conf &]

#这样做是指定配置文件,同时可以避免出500错误

6)确认已经运行:
[ps aux|grep vsftpd]



7)测试.


ftp localhost 10021
Connected to localhost (127.0.0.1).
220 ready, dude (vsFTPd 1.1.0: beat me, break me)
Name (localhost:chris): tom
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls
227 Entering Passive Mode (127,0,0,1,117,135)
150 Here comes the directory listing.
226 Transfer done (but failed to open directory). # 仅仅因为目录并非可列表的,忽略
ftp> size hosts # 查看文件名为"hosts"的文件的大小
213 147
ftp> get hosts # 下载文件名为"hosts"的文件

# 如果有错误请反馈!
空心菜
03-07-24, 09:54
该如何才能让用户列表呢,而且我想让他上传,是不是
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
quanliking
03-10-10, 13:51
README

本例将说明如何建立 vsftpd / PAM 来支持 ”虚拟用户“。
虚拟用户是一个登录用户,但它不像系统中真实用户做的那样,所以实际并不存在。
虚拟用户也因此比真实用户更加安全,因为该带有折衷味道的帐号只能用于 FTP 服务。

虚拟用户经常被用来给系统非信任用户提供可访问内容,而不允许一般公众访问。

第一步) 建立虚拟用户数据库

我们将使用 pam_userdb 来作虚拟用户认证。这会需要一个 username / password "db" 格式的文件,首先建立一个明文文件,该文件包含多行,用户名和密码交替出现,
请看样例文件 "logins.txt" - 该文件指定用户 "tom" 和密码 "foo" 以及 用户 "fred" 和密码 "bar"。

如果现在你是以 root 登录系统的,如下建立一个实际的数据库文件:

db_load -T -t hash -f logins.txt /etc/vsftpd_login.db
(需要安装 Berkeley db 程序)。

这样将创建 /etc/vsftpd_login.db 文件。显然,你会想要限制权限:

chmod 600 /etc/vsftpd_login.db

关于维护登录数据库的更多信息,请看文档 "Berkeley DB",等等。
http://www.sleepycat.com/docs/utility/index.html

第二步)使用你的新数据库创建 PAM 文件。

请看样例文件 vsftpd.pam。包含两行:
auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login
account required /lib/security/pam_userdb.so db=/etc/vsftpd_login

它们告诉 PAM 使用我们新的数据库来认证用户。复制该 PAM 文件到 PAM 目录 - 一般在 /etc/pam.d/
cp vsftpd.pam /etc/pam.d/ftp

第三步)为虚拟用户建立文件存放位置

useradd -d /home/ftpsite virtual
ls -ld /home/ftpsite
(类似下面):
drwx------ 3 virtual virtual 4096 Jul 30 00:39 /home/ftpsite

创建了一位用户叫 "virtual" ,他的家目录在 "/home/ftpsite" 。
让我们给这块下载区增加一些内容:
cp /etc/hosts /home/ftpsite
chown virtual.virtual /home/ftpsite/hosts

第四步)建立你的 vsftpd.conf 配置文件

请看该目录中的样例。让我们一行一行地仔细检查:
anonymous_enable=NO
local_enable=YES

为了安全禁用了匿名 FTP,而打开了非匿名 FTP(这是虚拟用户需要的)。

write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO

以上目的是保证安全,不允许任何写命令。

chroot_local_user=YES

该行确保虚拟用户被限制于虚拟 FTP 区(即我们在上面建立的 /home/ftpsite 目录)。

guest_enable=YES
guest_username=virtual

guest_enable 选项很重要 - 它激活了虚拟用户!同时 guest_username 行表示所有的虚拟用户被映射到真实用户 "virtual"(我们在上面已经增加的)。这行也限定了虚拟用户在文件系统中的终结区域 - 用户 "virtual" 的家目录,/home/ftpsite。

listen=YES
listen_port=10021

第一行使 vsftpd 工作在 "standalone" 模式 - 如,不必从 inetd 运行。
意味着你只要运行 vsftpd 的可执行文件,就能让它运行起来。
第二行使得 vsftpd 在非标准端口 10021 监听 FTP 请求(通常 FTP 使用 21 端口)。

pasv_min_port=30000
pasv_max_port=30999

以上为被动 FTP 接入请求设置端口范围 - 如果你正在配置防火墙将非常有用。
复制样例 vsftpd.conf 文件到 /etc:
cp vsftpd.conf /etc/

第五步)启动 vsftpd

转到 vsftpd 二进制文件存放目录,运行:
./vsftpd

如果一切正常,该命令会待在那里。如果有错误发生,你很可能会看到一些错误消息。

第六步)测试

另外运行一个 shell 线程 (或用 CTRL-Z 将 vsftpd 转入后台,然后 "bg")。
这里有一个 FTP 线程样例:
ftp localhost 10021
Connected to localhost (127.0.0.1).
220 ready, dude (vsFTPd 1.1.0: beat me, break me)
Name (localhost:chris): tom
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls
227 Entering Passive Mode (127,0,0,1,117,135)
150 Here comes the directory listing.
226 Transfer done (but failed to open directory).
ftp> size hosts
213 147
ftp>

备注:
我们提供的秘密是 "foo"。
看到 "failed to open directory" 清不要惊慌(假如我们想要使用 anon_world_readable_only=NO 就能够改变该作用,但可能为了安全我们会想要这种方式)。
我们会看到我们能通过 size(译注:估计是笔误,可能是 site) 命令访问 "hosts" 文件,该文件是我们事先拷贝到虚拟 FTP 区的。
quanliking
03-10-10, 14:44
README

本例说明如何扩充“虚拟用户”样例,来考虑稍复杂一些的设置要求。

假设我们想要两种类型的虚拟用户 - 一个只能浏览和下载内容,另一个不仅可以下载已有内容,而且能上传新内容。

为了实现这种设置,我们可以使用 vsftpd 强大的单用户配置能力(v.1.1.0 新增)

在前一个虚拟用户样例,我们创建了两个用户 - tom 和 free。
约定想让 fred 有写权限从而来实现上传新文件,而 tom 只能下载。

第一步)激活单用户配置功能。

为了激活这个强大的 vsftpd 特性,给 /etc/vsftpd.conf 加入以下行:

user_config_dir=/etc/vsftpd_user_conf

同时,建立该目录:

mkdir /etc/vsftpd_user_conf

第二步) 给予 tom 读取所有文件和目录的权限。

在上一个样例结束时,我们注意到虚拟用户只能看到泛读(world-readable)文件和目录。我们能够让 /home/ftpsite 目录泛读,同时可以上传具有泛读权限的文件。不过另外一种实现方法是给于 tom 下载非泛读文件的能力。

对 tom 用户,提供一个额外配置设置项来覆盖 anon_world_readable_only 选项:

echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/tom

检查一下 - 以 tom 登录,现在 "ls" 将返回一个目录列表!
以 fred 登录却不能。

注意 - 重启 vsftpd 获取配置文件 /etc/vsftpd.conf 的变化。(高级用户可以给vsftpd 监听进程发送 SIGHUP 信号)。

第三步)给予 fred 读取所有文件和目录的能力以及创建新文件,但不能影响已有的文件。

echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/fred
echo "write_enable=YES" >> /etc/vsftpd_user_conf/fred
echo "anon_upload_enable=YES" >> /etc/vsftpd_user_conf/fred

检查一下 - 以 tom 登录,你不能上传。以 fred 登录可以上传!
尝试删除一个文件,不论 tom 还是 fred 都不可以。
vBulletin v3.5.4,版权所有 ©2000-2007,Jelsoft Enterprises Ltd.
創作者介紹

創造心理的感動

gisanfu 發表在 痞客邦 PIXNET 留言(0) 人氣()