FTP

FTP:File Transfer Protocol   文件传输协议   

ftp服务可以使 主机间共享文件和传输数据, 它属于 网络协议 组的 应用层,工作于TCP/IP 协议的21号端口,它的优点是可以促进文件盒数据的共享,但是由于ftp服务是明文传输,可能导致密码和数据的泄露。
 
常见的ftp服务器端程序:
        wu-ftpd: 华盛顿大学研发
vsftpd: very Secure ftp Daemon    安全性高
proftpd: 
pureftpd: 
Filezilla
windows的ftp服务器“
Serv-U
Filezilla(开源)
 
客户端程序:
CLI:
ftp
lftp
GUI:
gftpd
FlashFXP
Cuteftp
Filezilla
 
vsftpd:   红帽中的rpm包是vsftpd,主要着眼于安全性
/etc/vsftpd: 配置文件目录(rpm)
/etc/init.d/vsftpd: 服务脚本
/usr/sbin/vsftpd: 主程序
基于PAM实现用户认证
/etc/pam.d/*          
/lib/security/*       认证模块
/lib64/security/*      64位系统,认证模块在这儿
支持虚拟用户
vsftpd: /var/ftp: 提供服务的根目录,这个目录对于vsftpd这个进程来说,是不能有写权限的,不允许除了root用户以外,其它用户有写权限 文件目录,其它用户不能有写权限,这是一种安全保证  
 
ftp: 用户
匿名用户 --> 有一个与之对应的系统用户
系统用户
虚拟用户 --> 有一个与之对应的系统用户
以上三种用户,都要映射为系统用户
/var/ftp: ftp用户的家目录
匿名用户默认访问的目录    因为匿名用户被映射为ftp用户
 
下面我们使用vsftpd来构建一个简单的ftp服务器
1、关闭selinux,setenforce 0,永久关闭请编辑配置文件/etc/selinux/config使SELINUX=permissive,然后再执行setenforce 0,执行getenforce可查看是否关闭
2、配置yum源
3、装载开发组环境 yum groupinstall "Development Tools" "Development Libraries"
 
1、yum install vsftpd 
安装后生成的部分文件介绍:

2、ftp服务的运行者

3、在windows命令行界面下,匿名登录

4、vsftpd的配置文件部分选项介绍,及其部分配置图解

 
    
  1. 配置文件/etc/vsftpd/vsftpd.conf中的部分选项介绍: 
  2. 想详细了解选项问题:man vsftpd.conf 
  3. anonymous_enable=                            #是否开放匿名用户 
  4. local_enable =                               #是否开放系统用户 
  5. write_enable=                                #是否能上传文件的(定义的是系统用户) 
  6. listen=YES                                   #表示vsftpd是否工作为独立守护进程 
  7. anon_upload_enable=                          #是否允许匿名用户上传文件 
  8. anon_mkdir_write_enable=                     #是否允许创建目录 
  9. dirmessage_enable=YES                        #当用户进入一个目录时,是否显示欢迎信息的    
  10. xferlog_enable=YES                           #是否打开传输日志 
  11. xferlog_file=/var/log/xferlog                #打开这项才能看日志的  
  12.  
  13. xferlog_std_format=YES                       #日志文件是否显示为标准格式  
  14. #chown_uploads=YES                           #当用户上传完文件后,是否把属主改了 
  15. #chown_username=whoever                      #改为谁 
  16.   
  17. chroot_list_enable=YES                       #是不是用一个文件将特定用户锁在它的家目录下 
  18. chroot_list_file=/etc/vsftpd/chroot_list     #在哪创建一个用户列表,所有在列表中的用户都将锁在
  19. 用户家目录下 
  20.   
  21. 加一行:chroot_local_user=YES                #表示所有用户都被禁锢在家目录下 

/etc/vsftpd/ftpusers #所有写在这个文件中的用户都禁止访问ftp服务器

userlist_enable=YES #使用这个列表中的用户来控制用户登录的

userlist_deny=YES #这个列表中的用户拒绝登录ftp服务器

userlist_deny=NO #仅允许这个列表中的用户登录ftp

 

 
    
  1. [root@mail ~]# echo "redhat" | passwd --stdin peter  
  2. Changing password for user peter. 
  3. passwd: all authentication tokens updated successfully. 
  4. [root@mail ~]# cp /etc/inittab /home/peter  #复制一个文件至peter的家目录下
  5. [root@mail ~]# cd /etc/vsftpd 
  6. [root@mail vsftpd]# ftp 172.16.25.3 
  7. Connected to 172.16.25.3. 
  8. 220 (vsFTPd 2.0.5) 
  9. 530 Please login with USER and PASS. 
  10. 530 Please login with USER and PASS. 
  11. KERBEROS_V4 rejected as an authentication type 
  12. Name (172.16.25.3:root): peter 
  13. 331 Please specify the password. 
  14. Password: 
  15. 230 Login successful. 
  16. Remote system type is UNIX. 
  17. Using binary mode to transfer files. 
  18. ftp> ls 
  19. 227 Entering Passive Mode (172,16,25,3,55,140) 
  20. 150 Here comes the directory listing. 
  21. 226 Directory send OK. 
  22. ftp> ls 
  23. 227 Entering Passive Mode (172,16,25,3,116,15) 
  24. 150 Here comes the directory listing. 
  25. -rw-r--r--    1 0        0            1666 Apr 17 20:10 inittab 
  26. 226 Directory send OK. 
  27. ftp> pwd 
  28. 257 "/home/peter" 
  29. ftp> cd /etc  #用户可以访问其他目录,没有锁定在其家目录下
  30. 250 Directory successfully changed. 
  31. ftp> ls 
  32. 227 Entering Passive Mode (172,16,25,3,88,24) 
  33. 150 Here comes the directory listing. 
  34. -rw-r--r--    1 0        0            2518 May 11  2011 DIR_COLORS 
  35. -rw-r--r--    1 0        0            2420 May 11  2011 DIR_COLORS.xterm 
  36. -rw-r--r--    1 0        0           92794 May 29  2007 Muttrc 
  37. -rw-r--r--    1 0        0               0 May 29  2007 Muttrc.local 
  38. drwxr-xr-x    4 0        0            4096 Mar 29 13:34 NetworkManager 
  39. drwxr-xr-x    9 0        0            4096 Mar 29 13:46 X11 
  40. -rw-r--r--    1 0        0            2562 Jan 15  2008 a2ps-site.cfg 

 

# 文件服务权限:文件系统权限*文件共享权限

5、匿名用户上传文件

# cd /etc/vsftpd/




 

 
    

匿名用户映射为了ftp用户,虽然ftp服务的进程的执行者是ftp用户,但是/var/ftp和/var/ftp/pub目录的属主和属组

都是root用户,所以虽然开启了允许匿名用户上传文件的选项,但其还没读写的权限,我们创建一个目录,给ftp用户

读写执行权限

 
    
  1. [root@mail vsftpd]# ftp 172.16.25.3 
  2. Connected to 172.16.25.3. 
  3. 220 (vsFTPd 2.0.5) 
  4. 530 Please login with USER and PASS. 
  5. 530 Please login with USER and PASS. 
  6. KERBEROS_V4 rejected as an authentication type 
  7. Name (172.16.25.3:root): ftp 
  8. 331 Please specify the password. 
  9. Password: 
  10. 230 Login successful. 
  11. Remote system type is UNIX. 
  12. Using binary mode to transfer files. 
  13. ftp> ls 
  14. 227 Entering Passive Mode (172,16,25,3,161,139) 
  15. 150 Here comes the directory listing. 
  16. drwxr-xr-x    2 0        0            4096 Dec 05  2011 pub 
  17. drwxrwxr-x    2 0        0            4096 Apr 17 20:33 upload 
  18. 226 Directory send OK. 
  19. ftp> cd upload 
  20. 250 Directory successfully changed. 
  21. ftp> lcd /etc 
  22. Local directory now /etc 
  23. ftp> put fstab 
  24. local: fstab remote: fstab 
  25. 227 Entering Passive Mode (172,16,25,3,131,221) 
  26. 150 Ok to send data. 
  27. 226 File receive OK. 
  28. 684 bytes sent in 0.043 seconds (15 Kbytes/s) 
  29. ftp> ls 
  30. 227 Entering Passive Mode (172,16,25,3,24,127) 
  31. 150 Here comes the directory listing. 
  32. -rw-------    1 14       50            684 Apr 17 20:37 fstab 
  33. 226 Directory send OK. 
  34. ftp>  
6、删除和创建目录

 
    
  1. [root@mail vsftpd]# service vsftpd restart 
  2. Shutting down vsftpd:                                      [  OK  ] 
  3. Starting vsftpd for vsftpd:                                [  OK  ] 
  4. [root@mail vsftpd]# ftp 172.16.25.3 
  5. Connected to 172.16.25.3. 
  6. 220 (vsFTPd 2.0.5) 
  7. 530 Please login with USER and PASS. 
  8. 530 Please login with USER and PASS. 
  9. KERBEROS_V4 rejected as an authentication type 
  10. Name (172.16.25.3:root): ftp 
  11. 331 Please specify the password
  12. Password
  13. 230 Login successful. 
  14. Remote system type is UNIX. 
  15. Using binary mode to transfer files. 
  16. ftp> ls 
  17. 227 Entering Passive Mode (172,16,25,3,253,29) 
  18. 150 Here comes the directory listing. 
  19. drwxr-xr-x    2 0        0            4096 Dec 05  2011 pub 
  20. drwxrwxr-x    2 0        0            4096 Apr 17 20:37 upload 
  21. 226 Directory send OK. 
  22. ftp> cd upload 
  23. 250 Directory successfully changed. 
  24. ftp> ls 
  25. 227 Entering Passive Mode (172,16,25,3,239,197) 
  26. 150 Here comes the directory listing. 
  27. -rw-------    1 14       50            684 Apr 17 20:37 fstab 
  28. 226 Directory send OK. 
  29. ftp> mkdir lsq  #成功创建目录
  30. 257 "/upload/lsq" created 
  31. ftp> ls 
  32. 227 Entering Passive Mode (172,16,25,3,187,136) 
  33. 150 Here comes the directory listing. 
  34. -rw-------    1 14       50            684 Apr 17 20:37 fstab 
  35. drwx------    2 14       50           4096 Apr 17 20:50 lsq 
  36. 226 Directory send OK. 
  37. ftp> delete lsq 
  38. 550 Delete operation failed. 
  39. ftp> ls 
  40. 227 Entering Passive Mode (172,16,25,3,164,33) 
  41. 150 Here comes the directory listing. 
  42. -rw-------    1 14       50            684 Apr 17 20:37 fstab 
  43. drwx------    2 14       50           4096 Apr 17 20:50 lsq 
  44. 226 Directory send OK. 
  45. ftp> delete fstab  #成功删除目录
  46. 250 Delete operation successful. 
  47. ftp> ls 
  48. 227 Entering Passive Mode (172,16,25,3,39,238) 
  49. 150 Here comes the directory listing. 
  50. drwx------    2 14       50           4096 Apr 17 20:50 lsq 
  51. 226 Directory send OK. 
  52. ftp>  

7、怎样锁定用户在其家目录下

以上就是ftp服务,部分可以启用的选项的应用,大家可以动手做做,了解一下其它选项的作用,这里就不一一介绍了!
下一篇配置vsftpd+pam+mysql