1.ftp全称为文件传输协议
利用ftp可以给用户提供上传和下载的文件服务
采用的是客户机/服务器模式
控制链接:是端口21,用于命令的
数据连接:是端口20,用于下载和传输的
数据链接的建立类型:
主动模式:是客户端请求链接,服务器打开数据链接端口20
被动模式:是客户机请求链接,客户机打开数据链接端口
3.ftp的主动模式:
客户端代开大于1024端口请求ftp的21端口进行控制连接,客户端给服务器的21端口发送port命令通告自己代开了1100端口(动态生成)
服务器段的20端口打开了数据链接
4.ftp的被动模式
客户机随机生成端口与服务器的21端口建立控制链接,客户段给服务器段21端口发动pasv命令通告自己要用被动模式与服务器通信
服务端口告诉客户机将打开一个固定端口,客户机与这个固定端口进行链接。
常见的ftp服务器程序
lls,serv-u
wu-ftpd。proftpd
vsftpd(very secure ftp daemon)最常用
常见的ftp客户端程序
vsftpd软件包(官网上下载)
5.ftp用户的类型
匿名用户:ftp,anonymouse(权限比较小)
本地用户:p 帐号名称,密码等信息保存在passwd,shadow
虚拟用户:p 使用独立帐号/密码的数据文件
6.默认的ftp服务器的功能
匿名用可以下载不可长传,不能切换到根目录
本地用户可以上传此奥在,可以切换到根目录,默认是可以切换到家目录之外的文件。
7.配置文件/etc/vsftpd/vsftpd.conf内容
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES 匿名用户登录
#
# Uncomment this to allow local users to log in.
local_enable=YES 本地用户登录
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES 本地用户的写权限
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022 本地权限掩码
#anon_mkdir_write_enable=YES 匿名用户可以进行建立和写的权限
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES 客户机在访问服务器之后,进入文件时候会有文件的相关说明
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES 用户在访问服务器时候的行为都是被记录下来
#
Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES 主动链接的端口为20
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog 访问行文记录文件
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES 独立监听(独立启动服务和非独立启动服务)
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd 这个是pan模块的名字, 我们放置在这个目录里面
userlist_enable=YES
tcp_wrappers=YES
6.常用的ftp命令
--verbose显示详细信息
--reverse上传文件
7。设置ftp的配置文件
匿名用户的基本设置
anonymous_enable=YES \\允许匿名用户下载文件
anon_upload_enable=YES \\允许匿名用户上传文件,但在服务器的文件系统中必须具有写入的权限
anon_mkdir_write_enable=YES \\允许匿名用户创建目录
anon_other_write_ebale=YES \\匿名用户可以删除文件
anon_max_rate=10240 \\设置匿名用户的最大传输速率,单位为字节
本地用户的限制设置
local_root=/var/ftp/sxjy \\限制本地用户的登录目录
chroot_local_user=YES \\是否将本地所有用户限制在家目录下
chroot_list_enable=YES \\启用用户列表
chroot_list_file=/etc/vsftpd/chroot_list //将本地用户限制在家目录里面,不能出去/文件是手动建立的
userlist_enable=YES \\是否启用/etc/vsftpd/user_list文件
userlist_deny=YES \\对于/etc/vsftpd/user_list文件里面的用户是允许或拒绝登录
8.在linux中添加ftp用户,并设置相应的权限
(1)、被限制用户名为user。
被限制路径为/home/user
(2)、建用户,命令行状态下,在root用户下:
命令:“useradd -d /home/user user” //增加用户user,并制定user用户的主目录为/home/user
passwd user 设置密码,运行后输入两次相同密码
(3)、更改用户相应的权限设置:
命令:“usermod -s /sbin/nologin user” //限定用户test不能telnet,只能ftp
命令:“usermod -s /sbin/bash user //用户test恢复正常
(4)、限制用户只能访问/home/test,不能访问其他路径
修改/etc/vsftpd/vsftpd.conf如下:
chroot_list_enable=YES //限制匿名用户访问自身目录 # (default follows) chroot_list_file=/etc/vsftpd/vsftpd.chroot_list //vsftpd.chroot_list只要用户在这个文件里九限制了用户只能访问家目录
编辑上面的内容
第一行:chroot_list_enable=YES //限制访问自身目录
第三行:编辑vsftpd.chroot_list。根据第三行说指定的目录,找到chroot_list文件。(因主机不同,文件名也许略有不同)
编辑vsftpd.chroot_list,将受限制的用户添加进去,每个用户名一行
(5)重启服务器
改完配置文件,不要忘记重启vsFTPd服务器
运行命令:/etc/init.d/vsftpd restart
(6)、如果需要允许用户修改密码,但是又没有telnet登录系统的权限:
运行命令:“usermod -s /usr/bin/passwd test” //用户telnet后将直接进入改密界面
max_clients=2 //最大链接数
max_login_fails=3 //允许数输入密码次数,超出就会锁定
max_per_ip=5 //限制用户下载量
pasv_max_port=65000 //被动模式的时候,限制动态的端口
--------------------------------------------------------------------------------常见错误--------------------------------------------------------------
1.[root@localhost ~]# ftp 192.168.73.128
ftp: connect: 没有到主机的路由
ftp>
解决方法:iptables防火墙没有设置 开放21端口规则,同理于23端口等其他端口。
查看端口是 netstat -anpul
[root@localhost ~]# iptables -A INPUT -p tcp --dport 21
[root@localhost ~]# service iptables restart
iptables:清除防火墙规则: [确定]
iptables:将链设置为政策 ACCEPT:nat mangle filter [确定]
iptables:正在卸载模块: [确定]
2.服务器的文件权限是不能为7的 ,也就是所有权限都是可用的,这样会导致文件不能使用的。