Chinaunix首页 | 论坛 | 博客
  • 博客访问: 480171
  • 博文数量: 82
  • 博客积分: 3003
  • 博客等级: 中校
  • 技术积分: 1285
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-11 15:27
文章分类

全部博文(82)

文章存档

2011年(1)

2010年(5)

2009年(63)

2008年(13)

我的朋友

分类: LINUX

2009-11-30 11:06:29

FTP

访问模式

主动模式

1Client(随机端口X)----->Server(21端口) [控制连接]

Client连接Server 21端口,告诉Server,我打开了X端口,你往我的X端口发送数据。

2Server(20端口)----->Client(指定端口X) [数据连接]

Server使用20端口向ClientX端口发送数据。

被动模式

1Client(任意Y)----->Server(21端口) [控制连接]

Client连接Server 21端口,我要传输数据,你告诉我你打开的端口。

2Server(21端口)----->Client(Y端口) [控制连接]

告诉Client我打开了P端口。

3Client(随机端口Z)----->Server(随机端口P) [数据连接]

Client打开随机端口Z,连接ServerP端口进行数据传输。

常用的FTP服务端和客户端:

Server

vsftpd: vsftpd

gssftp: krb5-workstation-servers

wuftp (no support)

proftpd (no support)

Client

Ftp

lftp

gftp

vsftpd配置文件

常用配置文件

/etc/vsftpd/vsftpd.conf (主配置文件)

/etc/vsftpd/ftpusers (用于访问控制)

/etc/vsftpd/user_list (用于访问控制)

PAM file: /etc/pam.d/vsftpd

常用配置选项

1、匿名用户限制(Anonymous user access

anon_root

匿名用户的主目录

anonymous_enable

是否允许匿名访问

write_enable

是否允许写入

anon_umask

匿名用户创建文件的掩码,默认为077,注意必须以0为前缀,否则会被当作 10进制整数。

anon_upload_enable (with write_enable)

是否允许匿名用户上传

anon_mkdir_write_enable (with write_enable)

是否允许匿名用户建立目录

anon_other_write_enable (delete & rename)

是否允许除了upload和创建目录之外的写操作,比如删除和重命名。默认为 NO

anon_world_readable_only (download files world readable)

待查

When enabled, anonymous users will only be allowed to download files

which are world readable. This is recognising that the ftp user may own

files, especially in the presence of uploads.

Default: YES

2、本地用户限制(Local user access

local_enable

是否允许匿名访问

write_enable

是否可写

local_umask

本定用户创建文件的掩码,同anon_umask

local_root

本地用户家目录

3、访问控制(Access Control

Host-based

tcp_wrappers=YES

User-based

PAM

pam_service_name=vsftpd /etc/vsftpd/vsftpd.conf

/etc/pam.d/vsftpd (pam_listfile.so)

/etc/vsftpd/ftpusers

userlist

userlist_enable

userlist_file: /etc/vsftpd/user_list

userlist_deny=YES/NO

userlist_deny只有在 userlist_enableYES的时候才生效,如果

userlist_denyNO,只有在userlist_file中指定的用户才可以登录

4chroot

5、虚拟用户(Virtual User

1、创建虚拟用户数据库

我们将使用pam_userdb模块来认证虚拟用户。

#cd /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS

#vim logins.txt ##用户名和密码交替,tom密码为foojerry的为redhat

tom

foo

jerry

redhat

#rpm -ivh db4-utils-4.3.29-9.fc6.i386.rpm ##安装db工具包

#db_load -T -t hash -f logins.txt /etc/vsftpd/login.db

#chmod 600 /etc/vsftpd/login.db

2、创建pam文件

#cat vsftpd.pam

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

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

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

其中ftp是在vsftpd.confpam_service_name=ftp指定

3、创建用户,用做虚拟用户映射

#useradd -d /home/virtual virtual

#ls -ld /home/ virtual

drwx------ 3 virtual virtual 4096 Jul 30 00:39 /home/virtual

4、编辑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

pam_service_name=ftp

5、重启vsftpd服务

6、测试

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

6、半虚拟用户

实现每个用户单个配置文件
1、#vim /etc/vsftpd.conf添加
    user_config_dir=/etc/vsftpd_user_conf
2、创建存放配置文件的目录
    mkdir /etc/vsftpd_user_conf
3、    创建单人配置文件
    为tom设置个人的配置
    echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/tom
    echo "write_enable=NO" >> /etc/vsftpd_user_conf/tom
    为luck设置个人的配置
    echo "anon_world_readable_only=NO" > /etc/vsftpd_user_conf/luck
    echo "write_enable=YES" >> /etc/vsftpd_user_conf/luck
    echo "anon_upload_enable=YES" >> /etc/vsftpd_user_conf/luck
阅读(1746) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~