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的配置文件部分选项介绍,及其部分配置图解
- 配置文件/etc/vsftpd/vsftpd.conf中的部分选项介绍:
- 想详细了解选项问题:man vsftpd.conf
- anonymous_enable= #是否开放匿名用户
- local_enable = #是否开放系统用户
- write_enable= #是否能上传文件的(定义的是系统用户)
- listen=YES #表示vsftpd是否工作为独立守护进程
- anon_upload_enable= #是否允许匿名用户上传文件
- anon_mkdir_write_enable= #是否允许创建目录
- dirmessage_enable=YES #当用户进入一个目录时,是否显示欢迎信息的
- xferlog_enable=YES #是否打开传输日志
- xferlog_file=/var/log/xferlog #打开这项才能看日志的
- xferlog_std_format=YES #日志文件是否显示为标准格式
- #chown_uploads=YES #当用户上传完文件后,是否把属主改了
- #chown_username=whoever #改为谁
- chroot_list_enable=YES #是不是用一个文件将特定用户锁在它的家目录下
- chroot_list_file=/etc/vsftpd/chroot_list #在哪创建一个用户列表,所有在列表中的用户都将锁在
- 用户家目录下
- 加一行:chroot_local_user=YES #表示所有用户都被禁锢在家目录下
/etc/vsftpd/ftpusers #所有写在这个文件中的用户都禁止访问ftp服务器
userlist_enable=YES #使用这个列表中的用户来控制用户登录的
userlist_deny=YES #这个列表中的用户拒绝登录ftp服务器
userlist_deny=NO #仅允许这个列表中的用户登录ftp
- [root@mail ~]# echo "redhat" | passwd --stdin peter
- Changing password for user peter.
- passwd: all authentication tokens updated successfully.
- [root@mail ~]# cp /etc/inittab /home/peter #复制一个文件至peter的家目录下
- [root@mail ~]# cd /etc/vsftpd
- [root@mail vsftpd]# ftp 172.16.25.3
- Connected to 172.16.25.3.
- 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.25.3:root): peter
- 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 (172,16,25,3,55,140)
- 150 Here comes the directory listing.
- 226 Directory send OK.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,116,15)
- 150 Here comes the directory listing.
- -rw-r--r-- 1 0 0 1666 Apr 17 20:10 inittab
- 226 Directory send OK.
- ftp> pwd
- 257 "/home/peter"
- ftp> cd /etc #用户可以访问其他目录,没有锁定在其家目录下
- 250 Directory successfully changed.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,88,24)
- 150 Here comes the directory listing.
- -rw-r--r-- 1 0 0 2518 May 11 2011 DIR_COLORS
- -rw-r--r-- 1 0 0 2420 May 11 2011 DIR_COLORS.xterm
- -rw-r--r-- 1 0 0 92794 May 29 2007 Muttrc
- -rw-r--r-- 1 0 0 0 May 29 2007 Muttrc.local
- drwxr-xr-x 4 0 0 4096 Mar 29 13:34 NetworkManager
- drwxr-xr-x 9 0 0 4096 Mar 29 13:46 X11
- -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用户
读写执行权限
- [root@mail vsftpd]# ftp 172.16.25.3
- Connected to 172.16.25.3.
- 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.25.3:root): ftp
- 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 (172,16,25,3,161,139)
- 150 Here comes the directory listing.
- drwxr-xr-x 2 0 0 4096 Dec 05 2011 pub
- drwxrwxr-x 2 0 0 4096 Apr 17 20:33 upload
- 226 Directory send OK.
- ftp> cd upload
- 250 Directory successfully changed.
- ftp> lcd /etc
- Local directory now /etc
- ftp> put fstab
- local: fstab remote: fstab
- 227 Entering Passive Mode (172,16,25,3,131,221)
- 150 Ok to send data.
- 226 File receive OK.
- 684 bytes sent in 0.043 seconds (15 Kbytes/s)
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,24,127)
- 150 Here comes the directory listing.
- -rw------- 1 14 50 684 Apr 17 20:37 fstab
- 226 Directory send OK.
- ftp>
- [root@mail vsftpd]# service vsftpd restart
- Shutting down vsftpd: [ OK ]
- Starting vsftpd for vsftpd: [ OK ]
- [root@mail vsftpd]# ftp 172.16.25.3
- Connected to 172.16.25.3.
- 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.25.3:root): ftp
- 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 (172,16,25,3,253,29)
- 150 Here comes the directory listing.
- drwxr-xr-x 2 0 0 4096 Dec 05 2011 pub
- drwxrwxr-x 2 0 0 4096 Apr 17 20:37 upload
- 226 Directory send OK.
- ftp> cd upload
- 250 Directory successfully changed.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,239,197)
- 150 Here comes the directory listing.
- -rw------- 1 14 50 684 Apr 17 20:37 fstab
- 226 Directory send OK.
- ftp> mkdir lsq #成功创建目录
- 257 "/upload/lsq" created
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,187,136)
- 150 Here comes the directory listing.
- -rw------- 1 14 50 684 Apr 17 20:37 fstab
- drwx------ 2 14 50 4096 Apr 17 20:50 lsq
- 226 Directory send OK.
- ftp> delete lsq
- 550 Delete operation failed.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,164,33)
- 150 Here comes the directory listing.
- -rw------- 1 14 50 684 Apr 17 20:37 fstab
- drwx------ 2 14 50 4096 Apr 17 20:50 lsq
- 226 Directory send OK.
- ftp> delete fstab #成功删除目录
- 250 Delete operation successful.
- ftp> ls
- 227 Entering Passive Mode (172,16,25,3,39,238)
- 150 Here comes the directory listing.
- drwx------ 2 14 50 4096 Apr 17 20:50 lsq
- 226 Directory send OK.
- ftp>
7、怎样锁定用户在其家目录下
以上就是ftp服务,部分可以启用的选项的应用,大家可以动手做做,了解一下其它选项的作用,这里就不一一介绍了!
下一篇配置vsftpd+pam+mysql
转载于:https://blog.51cto.com/crazylsq/1181946