FTP

FTP

一.FTP简介和原理

FTP即文件传输协议, CS架构, Linux下搭建ftp服务器需要安装vsftpd服务
测试示例
web01(192.168.5.131)安装vsftpd服务端, web02(192.168.5.132)安装ftp客户端

  • vsftpd安装

    • yum -y install vsftpd
    • 安装后开启服务, service vsftpd start, 默认监听21端口
    • 关闭防火墙: chkconfig --level 2345 iptables offservice iptables stop
    • 关闭selinux: 修改/etc/selinux/config, 修改为SELINUX=disabled, reboot
  • ftp客户端安装

    • yum -y install ftp
    • 连接web01, 服务端需要关闭防火墙和selinux, 格式为 ftp 服务端 ftp web01
[root@web02 ~]# ftp web01
Connected to web01 (192.168.5.131).
220 (vsFTPd 2.2.2)
Name (web01:root): uar
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

  • ftp默认登录方式
    • 匿名用户 anonymous或ftp
    • 本地用户 使用Linux系统用户和密码
      • ftp默认使是明文传输, Linux可以使用命令tcpdump -i eth0 -nnX port 21抓包, 当客户端连接上后, 输入的用户名和密码就会被抓包工具抓到, 看到明文的r用户名和密码, 所以默认禁止使用root登陆到ftp服务端
    • 虚拟用户 管理员自定义的模拟用户

二. FTP配置文件

  • 主配置文件: /etc/vsftpd/vsftpd.conf
    • listen_address=192.168.5.132 设置监听的ip地址
    • listen_port=21 设置监听端口
    • download_enable=YES 能否下载
    • max_clients=1 显示并发客户端连接数
    • max_per_ip=0 显示同一ip地址的并发连接数
  • 用户访问权限控制文件(黑名单):
    • /etc/ftpusers
    • user_list

四. 客户端使用

  • 使用ftp命令登陆 ftp web01
    ftp交互模式指令如下
    • help 帮助
    • get 下载
    • mget 下载一批文件
    • put 上传
    • mput 上传一批文件
    • quit 退出
  • 在windows资源管理器地址栏输入ftp://[email protected]也可以连接到web01这台主机上
  • 在windows下使用其他软件, 如winscp, 新建连接, 选择ftp协议, 端口21, 输入主机地址, 用户名, 密码就可以登录

五. 匿名用户访问

[root@web02 ~]# ftp web01
Connected to web01 (192.168.5.131).
220 (vsFTPd 2.2.2)

匿名用户登录, 默认使用ftp用户, 登陆后默认家目录为/var/ftp/目录下

Name (web01: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> ls
227 Entering Passive Mode (192,168,5,131,135,215).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0            4096 Mar 22  2017 pub
226 Directory send OK.
ftp> 

/var/ftp目录权限为
drwxr-xr-x. 3 root root 4096 1月 21 18:47 /var/ftp/, 所以匿名用户(ftp)对该目录没有编辑权限, 也就是不能增删改目录中的文件, 所以也就不能上传文件;
建议更改/var/ftp/pub目录的所有者为ftp用户, 从而将文件上传到pub目录下

你可能感兴趣的:(FTP)