实验名称:配置ftp服务


实验过程:


步骤1:基本环境的配置


一台服务器,两台主机,同一网段。


步骤2:安装ftp软件包


由于配置IP和挂载镜像太简单,这里掠过。。直接上图


[root@dc Server]# rpm -ivh vsftpd-2.0.5-28.el5.x86_64.rpm


warning: vsftpd-2.0.5-28.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186


Preparing...                                                            (100########################################### [100%]


  1:vsftpd                                                             (  1########################################### [100%]


[root@dc Server]#


启动服务


[root@dc Server]# service vsftpd start


vsftpd 启动 vsftpd:                                    [确定]


[root@dc Server]# chkconfig vsftpd on


[root@dc Server]#



在这种情况下已经实现了匿名用户可上传无法下载,本地用户上传下载均可;


下面我们小小的测试一下


[root@localhost ~]# ftp 192.168.4.253


Connected to 192.168.4.253.


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 (192.168.4.253:root): chenduo


331 Please specify the password.


Password:


230 Login successful.


Remote system type is UNIX.


Using binary mode to transfer files.


ftp> ls


227 Entering Passive Mode (192,168,4,253,195,230)


150 Here comes the directory listing.


-rw-r--r--    1 500      500             0 Apr 15 06:07 3.txt


drwxrwxr-x    2 500      500          4096 Mar 31 03:59 c1


drwxrwxr-x    2 500      500          4096 Mar 31 03:34 cd


-rwxr-x---    1 0        0              26 Mar 31 04:18 d.c


226 Directory send OK.


ftp> pwd


257 "/home/chenduo"


ftp>


普通用户是可以访问的,下面我们读写一下,


ftp> get 3.txt


local: 3.txt remote: 3.txt


227 Entering Passive Mode (192,168,4,253,212,190)


150 Opening BINARY mode data connection for 3.txt (0 bytes).


226 File send OK.


ftp> put 1.txt


local: 1.txt remote: 1.txt


227 Entering Passive Mode (192,168,4,253,202,38)


150 Ok to send data.


226 File receive OK.


ftp>


发现本地用户是可以的。


下面换匿名用户,


ftp> get 2.txt


local: 2.txt remote: 2.txt


227 Entering Passive Mode (192,168,4,253,232,35)


150 Opening BINARY mode data connection for 2.txt (0 bytes).


226 File send OK.


ftp> put 2.txt


local: 2.txt remote: 2.txt


227 Entering Passive Mode (192,168,4,253,116,66)


550 Permission denied.


ftp> pwd


257 "/pub"


ftp>


证明是无法写入的。接下来配置匿名用户可以访问。


步骤3:进入修改主配置文件


27 anon_upload_enable=YES


28 #


29 # Uncomment this if you want the anonymous FTP user to be able to create


30 # new directories.


31 anon_mkdir_write_enable=YES


32 anon_other_write _enable=YES


保存退出,重启服务


由于访问权限和共享权限之间取交集,所以还需要修改pub文件的所有者或者为其添加acl


[root@dc ~]# chown ftp /var/ftp/pub/


[root@dc ~]#


步骤4:测试


下面测试


ftp> put 1.txt


local: 1.txt remote: 1.txt


227 Entering Passive Mode (192,168,4,253,180,62)


150 Ok to send data.


226 File receive OK.


ftp> pwd


257 "/pub"


ftp>


这样匿名用户就可以写入了,不过工作中一般不这么做,太危险,为了练习,我们需要这么做。



实验名称:验证ftp黑白名单


实验过程:


步骤1:基本环境


在实验2的基础上。建立三用户为了方便测试。


步骤2:修改主配置文件


本来应该进入黑名单配置文件修改,由于我技术好,这里直接echo


[root@dc ~]# echo chenduo >> /etc/vsftpd/ftpusers


[root@dc ~]# tail -n 1 /etc/vsftpd/ftpusers


chenduo


[root@dc ~]#


步骤3:测试


下面登录测试


Name (192.168.4.253:root): chenduo


331 Please specify the password.


Password:


530 Login incorrect.


Login failed.


ftp>


都不需要重启服务,瞬间进不去了


然后我们测试黑白名单,


先修改黑白名单属性,


120 userlist_deny=NO


再将用户chenduo1填入黑白名单


[root@dc ~]# echo chenduo1 >> /etc/vsftpd/user_list


[root@dc ~]# tail -n 1 /etc/vsftpd/user_list


chenduo1


[root@dc ~]#


访问测试


Name (192.168.4.253:root): chenduo1


530 Permission denied.


Login failed.


ftp>


怎么会结果不一样呢,我发现我忘记重启服务了,下面重启服务


[root@dc ~]# service vsftpd restart


关闭 vsftpd:                                              [确定]


vsftpd 启动 vsftpd:                                    [确定]


[root@dc ~]#


再测试


Name (192.168.4.253:root): chenduo1


331 Please specify the password.


Password:


230 Login successful.


Remote system type is UNIX.


Using binary mode to transfer files.


ftp>


没有任何问题


同时这个错误也证明了,黑白名单默认的是黑名单,也就是NO,如果修改成YES就为白名单。



实验名称:ftp其它功能


实验过程:


步骤1:环境


在实验三的基础上


步骤2:修改主配置文件


118 userlist_enable=YES


119 tcp_wrappers=YES


120 userlist_deny=NO


121 chroot_local_user=YES


122 #更改匿名用户的站点为/home/1/


123 anon_root=/home/1/


124 #更改本地用户的站点为/home/2/


125 local_root=/home/2/


126 #设置匿名用户的下载速率50K


127 anon_max_rate=50000


128 #本地用户下载速率100K


129 local_max_rate=100000


130 #最多20个并发


131 max_clients=20


132 #每IP地址最多两个并发


133 max_per_ip=2


~    


步骤3:测试


首先验证匿名用户是否被禁锢


Name (192.168.4.253: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> cd ..


250 Directory successfully changed.


ftp>  


发现无法回到上级目录,而且所在位置已经改变,为/home/1


下面我们来测速


[root@localhost ~]# wget ftp://192.168.4.253/1.txt


--2014-04-15 20:52:50--  ftp://192.168.4.253/1.txt


          => `1.txt'


Connecting to 192.168.4.253:21... 已连接。


正在以 anonymous 登录 ... 登录成功!


==> SYST ... 完成。    ==> PWD ... 完成。


==> TYPE I ... 完成。  ==> 不需要 CWD


==> SIZE 1.txt ... 1048576000


==> PASV ... 完成。    ==> RETR 1.txt ... 完成。


长度:1048576000 (1000M)


下面的复制不上,不过速度很慢,为40K


同样用chenduo用户下载,速度为100K左右。


至此试验完成

实验结果:FTP的配置选项还是挺多的,挺灵活的,而且这个服务可以跨平台,所以同样要做到秒杀。