竹子开花的时 发表于 2019-2-17 12:21:56

linux ftp

  ftp:   文件传输协议

  软件包: vsftpd
  ftp端口: 控制端口 21/tcp数据端口 20/tcp(主动模式)
  配置文件: /etc/vsftpd/vsftpd.confman vsftpd.confman smb.conf
  服务端配置:
  # yum -y install vsftpd
  # service vsftpd restart
  # grep ftp /etc/passwd
  ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
  # grep alice /etc/passwd
  alice:x:2008:2012::/home/alice:/bin/bash
  小总:vsftpd未做任何配置:
  1. 匿名用户仅能从被锁定的根目录下载文件/var/ftp
  2. 系统用户可以上传文件到他有写权限的任何目录,HOME目录未被锁定
  vsftpd支持的用户类型:
  匿名用户:ftp
  系统用户: alice,jack
  虚拟用户: 不存在于系统账号数据中,安全,例如mysql提供的用户账号
  从客户端测试:
  # yum -y install ftp lftp
  # ftp 192.168.2.115//输入用户名和口令
  # lftp 192.168.2.115//匿名用户
  # lftp alice@192.168.2.115//指定用户
  # wget ftp://192.168.2.80/rhel5.repo
  # wget ftp://192.168.2.80/rhel5.repo -O /etc/yum.repo.d/rhel5.repo
  # cat download.txt
  ftp://192.168.2.80/rhel5.repo
  ftp://192.168.2.80/raid.png
  # wget -i download.txt
  ========基本配置、访问控制========
  注意:空格,指令错误,指令重复
  # egrep -v '^#|^$' /etc/vsftpd/vsftpd.conf
  # cp /etc/vsftpd/vsftpd.conf{,.bak}备份配置文件
  anonymous_enable=YES//是否允许匿名用户登录
  local_enable=YES//是否允许本地用户登录
  write_enable=YES//是否允许写(全局)
  local_umask=022//控制本地用户上传文件的默认权限,umask表示要减掉的权限
  anon_umask=077//控制匿名用户上传文件的默认权限
  chroot: 锁定用户HOME,针对系统用户
  方法一:部分限制
  chroot_list_enable=YES
  chroot_list_file=/etc/vsftpd/chroot_list
  方法二:全部限制
  chroot_local_user=YES
  anon_max_rate=500000//匿名用户限速
  local_max_rate=80000//本地用户限速
  max_clients=500//ftp最大连接数
  max_per_ip=2//单个IP最大连接数,线程数
  local_root=/ftproot//指定本地用户访问的root目录
  anon_root=/anonroot//指定匿名用户访问的root目录
  案例1:
  1. 为各个部门建立ftp访问用户,包括部门的管理员
  # mkdir -p /ftproot/{hr/{hr01,hr02},it,sale}
  # chmod -R 777 /ftproot/
  # useradd admin -s /sbin/nologin
  # useradd hr_admin -s /sbin/nologin
  # useradd hr01_admin -s /sbin/nologin
  # useradd hr02_admin -s /sbin/nologin
  # useradd it_admin -s /sbin/nologin
  # useradd sale_admin -s /sbin/nologin
  # passwd admin
  ==================================================
  # for i in admin hr_admin hr01_admin hr02_admin it_admin sale_admin
  > do
  > useradd $i -s /sbin/nologin
  > echo 1 |passwd $i --stdin
  > done
  =========================================================================
  2. 配置FTP服务器
  注:使用匿名访问公司公共的资源
  ===主配置文件
  # vim /etc/vsftpd/vsftpd.conf
  write_enable=NO
  chroot_local_user=YES
  local_max_rate=100000
  max_per_ip=2
  user_config_dir=/etc/vsftpd/vsftpd_user_conf指定用户私有配置文件存放的目录
  # service vsftpd restart
  ===私有配置文件
  # mkdir /etc/vsftpd/vsftpd_user_conf
  # cd /etc/vsftpd/vsftpd_user_conf/
  # cat admin
  local_root=/ftproot
  write_enable=YES
  local_max_rate=0
  max_per_ip=0
  ===============vsftpd启动排错===================
  尝试启动
  # service vsftpd restart
  关闭 vsftpd:                                              [失败]
  为 vsftpd 启动 vsftpd:                                    [失败]
  查看该服务的端21/tcp是否被占用
  # netstat -tnlp |grep :21
  tcp      0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      3514/xinetd
  tcp      0      0 0.0.0.0:2105                0.0.0.0:*                   LISTEN      3514/xinetd
  使用lsof查看21/tcp被哪个进程占用
  # lsof -i TCP:21
  COMMANDPID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
  xinetd3514 root   17uIPv4   9902      0t0TCP *:ftp (LISTEN)
  # ls /etc/xinetd.d/
  chargen-dgram   daytime-streamecho-stream   klogin       rsync          time-stream
  chargen-streamdiscard-dgram   eklogin       krb5-telnettcpmux-server
  cvs             discard-streamekrb5-telnetkshell       tftp
  daytime-dgram   echo-dgram      gssftp      rmcp         time-dgram
  #
  # cd /etc/xinetd.d/
  # grep 21 *
  # grep ftp *
  gssftp:service ftp
  gssftp: server          = /usr/kerberos/sbin/ftpd
  rsync:# description: The rsync server is a good addition to an ftp server, as it \
  tftp:# description: The tftp server serves files using the trivial file transfer \
  tftp:#protocol.The tftp protocol is often used to boot diskless \
  tftp:service tftp
  tftp:   server                  = /usr/sbin/in.tftpd
  tftp:   server_args             = -s /tftpboot
  # cat gssftp
  # default: off
  # description: The kerberized FTP server accepts FTP connections \
  #            that can be authenticated with Kerberos 5.
  service ftp
  {
  disable = no
  flags         = REUSE
  socket_type   = stream
  wait            = no
  user            = root
  server          = /usr/kerberos/sbin/ftpd
  server_args   = -l -a
  log_on_failure+= USERID
  }
  # chkconfig gssftp off
  # service xinetd restart
  停止 xinetd:                                              [确定]
  启动 xinetd:                                              [确定]
  # lsof -i TCP:21
  # netstat -tnlp |grep :21
  tcp      0      0 0.0.0.0:2105                0.0.0.0:*                   LISTEN      4717/xinetd
  # service vsftpd restart
  关闭 vsftpd:                                              [失败]
  为 vsftpd 启动 vsftpd:                                    [确定]
  # netstat -tnlp |grep :80检查某个端口是否被占用



页: [1]
查看完整版本: linux ftp