Chinaunix首页 | 论坛 | 博客
  • 博客访问: 166029
  • 博文数量: 79
  • 博客积分: 2585
  • 博客等级: 少校
  • 技术积分: 840
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-08 16:28
个人简介

共同进步

文章分类

全部博文(79)

文章存档

2015年(6)

2014年(2)

2013年(1)

2012年(1)

2007年(69)

我的朋友
最近访客

分类: 系统运维

2015-12-21 12:29:55

1.1.1.1 Vsftp(安全的ftp

1.1.1.1.2       安装vsftp

[root@linux-node2 ~]# rpm -qa|grep vsftp

vsftpd-2.0.5-16.el5_5.1

[root@linux-node2 ~]#

 

1.1.1.1.3       配置文件说明

[root@linux-node2 vsftpd]# ll

total 20

-rw------- 1 root root  125 Apr  8  2010 ftpusers

-rw------- 1 root root  361 Apr  8  2010 user_list

-rw------- 1 root root 4579 Apr  8  2010 vsftpd.conf

-rwxr--r-- 1 root root  338 Apr  8  2010 vsftpd_conf_migrate.sh

[root@linux-node2 vsftpd]#

 

1ftpusers 是用户控制文件,在这个文件里面的用户,默认是不可以使用vsftpd 服务的。

2user_list 默认功能和第一个一样,但是通过配置,我们可以让只有在第二个文件里

的用户才能使用vsftpd 服务,这样新加入的用户就不会自动拥有vsftp 的使用权,这样可以

vsftpd 服务器更加安全

3vsftpd_conf_migrate.sh vsftpd 操作的一些变量和设置,这个不用管的

当然,主角就是vsftpd.conf ,配置vsftpd,我们操作最多的也就是这个文件了

配置文件详解:

[root@haproxy01 vsftpd]# cat vsftpd.conf

# Example config file /etc/vsftpd/vsftpd.conf

anonymous_enable=YES                   //是否允许匿名登录

local_enable=YES                        //是否允许本地用户登录

write_enable=YES                        //是否允许写

local_umask=022                        //设置mask值,定制文件或目录的默认权限

#anon_upload_enable=YES                //是否允许匿名上传文件

#anon_mkdir_write_enable=YES            //是否允许匿名用户创建目录

dirmessage_enable=YES                   //是否显示登录信息

xferlog_enable=YES                       //是否开启日志功能

#xferlog_file=/var/log/xferlog               //日志名称

xferlog_std_format=YES                      //是否使用标准格式

connect_from_port_20=YES                //是否使用20端口来传输数据

#chown_uploads=YES                     //文件上传后是否修改属主

#chown_username=whoever               //文件上传后修改属主名称

#idle_session_timeout=600                //会话空闲超时时限

#data_connection_timeout=120            //数据传输超时

#nopriv_user=ftpsecure                   //定义底层运行时的用户名,默认为nobody

#ascii_upload_enable=YES                 //定义是否可以使用ascii模式上传

#ascii_download_enable=YES               //定义是否可以使用ascii模式下载

#ftpd_banner=Welcome to blah FTP service.   //定义ftp登录欢迎辞

#chroot_list_enable=YES                   //定义是否开启chroot_list

#chroot_list_file=/etc/vsftpd/chroot_list      //定义chroot_list文件位置

listen=YES                              //standalone模式启动

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

anon_other_write_enable=YES // 允许匿名帐户删除、重命名

anon_root=/ftp // 更改匿名帐户根目录,默认为”/var/ftp

local_root=/local // 更改本地帐户根目录为/local,默认为用户主目录~

userlist_enable=YES // 开启用户列表功能

userlist_deny=YES // 用户列表文件中所有帐户全拒绝。NO 时,只有列表中用户能登陆

userlist_file=/etc/vsftpd.user_list // 用户列表文件

anon_max_rate=0 // 匿名用户最大传输速率,0为无限

local_max_rate=0 // 本地用户最大传输速率,0为无限

max_clients=0 // 最大客户端连接数,0为无限

pasv_max_port=0 // 客户端端口

 

[root@haproxy01 vsftpd]#

查看文件其它参数# man vsftpd.conf

 

 

1.1.1.1.4       配置实例一、(搭建匿名访问的ftp服务器)

 [root@linux-node2 vsftpd]# service vsftpd start

Starting vsftpd for vsftpd: [  OK  ]

[root@linux-node2 vsftpd]# service vsftpd status

vsftpd (pid 28250) is running...

[root@linux-node2 vsftpd]#

 

修改/etc/vsftpd/vsftpd.conf文件

anonymous_enable=YES

 

 

[root@linux-node2 ~]# ftp 172.16.1.10

Connected to 172.16.1.10.

220 (vsFTPd 2.0.5)

530 Please login with USER and PASS.

530 Please login with USER and PASS.

KERBEROS_V4 rejected as an authentication type

Name (172.16.1.10:root): anonymous    #以匿名用户登录

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp>

1.1.1.1.5       配置实例二、(搭建允许本地用户访问,不允许匿名)

修改/etc/vsftpd/vsftpd.conf文件中

anonymous_enable=YES

YES修改为NO  ,然后重启服务,如下匿名访问已不允许:

[root@linux-node2 ~]# ftp 172.16.1.10

Connected to 172.16.1.10.

220 (vsFTPd 2.0.5)

530 Please login with USER and PASS.

530 Please login with USER and PASS.

KERBEROS_V4 rejected as an authentication type

Name (172.16.1.10:root): anonymous

331 Please specify the password.

Password:

530 Login incorrect.

Login failed.

ftp>

 

以本地用户tom登录:

[root@linux-node2 vsftpd]# cat /etc/passwd |grep tom

tom:x:3004:3004::/home/tom:/bin/bash

[root@linux-node2 vsftpd]#

 

[root@linux-node2 ~]# ftp 172.16.1.10

Connected to 172.16.1.10.

220 (vsFTPd 2.0.5)

530 Please login with USER and PASS.

530 Please login with USER and PASS.

KERBEROS_V4 rejected as an authentication type

Name (172.16.1.10:root): tom

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> cd /etc      

250 Directory successfully changed.   ##可以切换到其他目录

ftp>

 

1.1.1.1.6       配置实例三、禁锢用户在自己的家目录

    修改/etc/vsftpd/vsftpd.conf

    chroot_list_enable=YES

    chroot_list_file=/etc/vsftpd/chroot_list

 

创建chroot_list文件,一行一个用户名

[root@linux-node2 vsftpd]# cat chroot_list

tom

[root@linux-node2 vsftpd]#

登录后尝试切换目录

[root@linux-node2 ~]# ftp 172.16.1.10

Connected to 172.16.1.10.

220 (vsFTPd 2.0.5)

530 Please login with USER and PASS.

530 Please login with USER and PASS.

KERBEROS_V4 rejected as an authentication type

Name (172.16.1.10:root): tom

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> cd /etc

550 Failed to change directory.

ftp> dir

227 Entering Passive Mode (172,16,1,10,24,53)

150 Here comes the directory listing.

drwx------    3 3004     3004         4096 Jul 09 08:58 mail

226 Directory send OK.

ftp>  

 

(注意:如果你启动了chroot 机制,却没有子啊/etc/vsftpd/下建立chroot_list 这个文件,那么当你登陆的时候会出现失败的字样具体如下:421 Service not available, remote server has closed connection,所以启用之后一定要建立chroot_list 文件的哦)

 

1.1.1.1.7       配置实例四、(搭建虚拟用户访问的ftp服务器)

首先创建用户名密码文件

touch vlogin.txt

ftpuser1

123456

ftpuser2

123456

 

奇数行是用户名,偶数行是密码

 

ü  使用db_load命令生成db数据库文件,前提是需要先安装db_load命令

[root@linux-node2 Server]# rpm -qa|grep db4

db4-4.3.29-10.el5_5.2

db4-utils-4.3.29-10.el5_5.2

db4-4.3.29-10.el5_5.2

[root@linux-node2 Server]#

 

ü  生成数据库:

[root@linux-node2 vsftpd]# db_load  -T -t hash -f /etc/vsftpd/vlogin.txt  /etc/vsftpd/vlogin.db

[root@linux-node2 vsftpd]# ls -ltr vlogin*

-rw-r--r-- 1 root root    32 Sep  6 21:51 vlogin.txt

-rw-r--r-- 1 root root 12288 Sep  6 21:51 vlogin.db

[root@linux-node2 vsftpd]#

 

ü  修改安全认证机制:

[root@linux-node2 ~]# cat /etc/pam.d/vsftpd

#%PAM-1.0

#session    optional     pam_keyinit.so    force revoke

auth       required     pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed

#auth       required    pam_shells.so

#auth       include     system-auth

#account    include     system-auth

#session    include     system-auth

#session    required     pam_loginuid.so

auth       required     pam_userdb.so   db=/etc/vsftpd/vlogin

account    required     pam_userdb.so   db=/etc/vsftpd/vlogin

[root@linux-node2 ~]#

 

注释原文件中其他行,添加标黄颜色的两行

 

ü  配置虚拟用户与实际用户的映射:

光有虚拟用户是无法登录系统的,需要让虚拟用户对应一个系统实际用户

useradd  -s /sbin/nologin ftp2

 

修改//etc/vsftpd/vsftpd.conf文件,添加如下几行

pam_service_name=vsftpd    ###配置vsftpd 使用的PAM 模块为vsftpd

user_config_dir=/etc/vsftpd/vuserconfig   ###设置虚拟帐号权限配置的主目录

userlist_enable=YES

guest_enable=yes              ####允许使用虚拟用户登陆FTP

guest_username=ftp2          ####虚拟用户所对应的系统用户为ftp2

tcp_wrappers=YES

 

内容选项解释:

max_clients=1:设置FTP 服务器最大接入客户端数为1

max_per_ip=1:设置每个IP 地址最大连接数为1

/etc/vsftpd/下建立vuserconfig 目录,用于存放用户的权限配置文件,以便为各个用户分配不同的权限,

 

ü  创建vuserconfig目录,并在目录下创建以用户名为名字的文件,进行用户权限设置

 [root@linux-node2 vuserconfig]# cat vuserconfig /ftpuser1

write_enable=yes

anon_mkdir_write_enable=yes

anon_world_readable_only=no

 

参数详解:

anon_world_readable_only=no 允许匿名用户浏览器整个服务器的文件系统

write_enable=yes 允许在文件系统写入权限

anon_mkdir_write_enable=yes 允许创建文件夹

anon_other_write_enable=yes 允许用户改名和删除文件的权限

anon_upload_enable=yes 开启匿名帐号的上传功能

 

 

登录测试:

[root@linux-node2 ~]# ftp 172.16.1.10

Connected to 172.16.1.10.

220 (vsFTPd 2.0.5)

530 Please login with USER and PASS.

530 Please login with USER and PASS.

KERBEROS_V4 rejected as an authentication type

Name (172.16.1.10:root): ftpuser1  ##虚拟用户1可以登录,设置了部分权限

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> dir

227 Entering Passive Mode (172,16,1,10,141,141)

150 Here comes the directory listing.

drwx------    2 3007     3007         4096 Sep 07 02:33 123

drwx------    2 3007     3007         4096 Sep 07 02:20 abc

226 Directory send OK.

ftp>

 

 

[root@linux-node2 ~]# ftp 172.16.1.10

Connected to 172.16.1.10.

220 (vsFTPd 2.0.5)

530 Please login with USER and PASS.

530 Please login with USER and PASS.

KERBEROS_V4 rejected as an authentication type

Name (172.16.1.10:root): ftpuser2   ##虚拟用户2可以登录,但没设置权限

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> dir

227 Entering Passive Mode (172,16,1,10,80,208)

150 Here comes the directory listing.

226 Transfer done (but failed to open directory).

ftp> cd /

250 Directory successfully changed.

ftp> dir

227 Entering Passive Mode (172,16,1,10,136,246)

150 Here comes the directory listing.

226 Transfer done (but failed to open directory).

ftp> mkdir aaa

550 Permission denied.

ftp>

 

 

1.1.1.1.8       配置实例五、(实现部分用户访问控制)

默认在/etc/vsftpd/ftpusers文件中的用户无法登录ftp

[root@linux-node2 vsftpd]# cat ftpusers

# Users that are not allowed to login via ftp

root

bin

......

nobody

[root@linux-node2 vsftpd]#

 

这是通过系统安全机制pam模块配置的,

[root@haproxy01 vsftpd]# cat /etc/pam.d/vsftpd

#%PAM-1.0

session    optional     pam_keyinit.so    force revoke

auth       required     pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed

auth       required     pam_shells.so

auth       include      system-auth

account    include      system-auth

session    include      system-auth

session    required     pam_loginuid.so

 

其中/lib/security/pam_listfile.so 是调用这个模块用来检测登陆进来的用户是不是记记载在/etc/ftpusers 中的用户

item=user 很明显是说明要检测的是用户

sense=deny 则是处理方法deny 就是就是拒绝的意思了

 

若要修改为只有在ftpusers文件中的用户才能访问ftp,则把sense=deny修改为allow即可。

 

要达到只允许部分用户登陆ftp 的方法还有一种:

通过修改配置文件,添加下面两行,这样就只有userlist 文件中的用户才可以登陆系统

userlist_enable=YES

userlist_deny=NO

阅读(1370) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~