用Linux架设FTP服务器(5)


 配置“/etc/ftphosts”文件
    “/etc/ftphosts”文件为每一个用户建立规则,指定允许用户从某个主机登录ftp服务器,或者不允许用户从某个主机登录ftp服务器。
    创建“ftphosts”文件(touch /etc/ftphosts),加入下面这几行:
    # Example host access file
    #
    # Everything after a ‘#‘ is treated as comment,
    # empty lines are ignored
    allow ftpadmin 208.164.186.1 208.164.186.2 208.164.186.4
    把文件的权限改为600:
    [root@deep]# chmod 600 /etc/ftphosts
    每一行可能是:
    allow <username> <addrglob>
    或
    deny <username> <addrglob>
    “allow”允许用户用<username>用户名,从<addrglob>地址访问ftp服务器。<addrglob>可以包含多个地址。
    “deny”禁止用户名为<username>的用户,从<addrglob>地址访问ftp服务器。<addrglob>可以包含多个地址。
    配置“/etc/ftpusers”文件
    “/etc/ftpusers”文件设置哪些用户不允许连接到ftp服务器。
    创建“ftpusers”文件(touch /etc/ftpusers),加入下面这几行:
    root
    bin
    daemon
    adm
    lp
    sync
    shutdown
    halt
    mail
    news
    uucp
    operator
    games
    nobody
    把文件的权限设成600:
    [root@deep]# chmod 600 /etc/ftpusers
    配置“/etc/ftpconversions”文件
    “/etc/ftpconversions”是用来控制当传输文件的时候是否进行压缩。
    创建“ftpconversions”文件(touch /etc/ftpconversions),在文件中加入:
    :.Z: : :/bin/compress -d -c %s:T_REG|T_ASCII:O_UNCOMPRESS:UNCOMPRESS
    : : :.Z:/bin/compress -c %s:T_REG:O_COMPRESS:COMPRESS
    :.gz: : :/bin/gzip -cd %s:T_REG|T_ASCII:O_UNCOMPRESS:GUNZIP
    : : :.gz:/bin/gzip -9 -c %s:T_REG:O_COMPRESS:GZIP
    : : :.tar:/bin/tar -c -f - %s:T_REG|T_DIR:O_TAR:TAR
    : : :.tar.Z:/bin/tar -c -Z -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+COMPRESS
    : : :.tar.gz:/bin/tar -c -z -f - %s:T_REG|T_DIR:O_COMPRESS|O_TAR:TAR+GZIP
    : : :.crc:/bin/cksum %s:T_REG::CKSUM
    : : :.md5:/bin/md5sum %s:T_REG::MD5SUM
  
    把文件的属性改为600:
    [root@deep]# chmod 600 /etc/ftpconversions
    配置“/etc/pam.d/ftp”文件
    配置“/etc/pam.d/ftp”文件使其支持PAM安全验证。
     创建“ftp”文件(touch /etc/pam.d/ftp)并加入:
    #%PAM-1.0
    auth required /lib/security/pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
    auth required /lib/security/pam_pwdb.so shadow nullok
    auth required /lib/security/pam_shells.so
    account required /lib/security/pam_pwdb.so
    session required /lib/security/pam_pwdb.so
    配置“/etc/logrotate.d/ftpd”文件
    配置“/etc/logrotate.d/ftpd”文件使得日志文件每周自动循环更新。
    创建“ftpd”文件(touch /etc/logrorate.d/ftpd)并加入:
    /var/log/xferlog {
    # ftpd doesn‘t handle SIGHUP properly
    nocompress
    }
    配置ftp使其使用inetd超级服务器(用于实现tcp-wrappers)
    tcp-wrappers用来启动和中止ftpd服务。当inetd执行的时候,它会从默认为“/etc/inetd.conf”的配置文件读入配置信息。配置文件中每一行中的项用TAB或空格隔开。
    编辑inetd.conf文件(vi /etc/inetd.conf),加入并验证是否存在下面这一行: ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a
    注意:更新完“inetd.conf”文件之后要发给inetd一个SIGNUP信号,运行下面的命令:
    [root@deep /root]# killall -HUP inetd
    编辑“hosts.allow”文件(vi /etc/hosts.allow)加入这一行:
    in.ftpd: 192.168.1.4 win.openarch.com
    这表示IP地址为“192.168.1.4”并且主机名为“win.openarch.com”的计算机允许访问ftp服务器。
    FTP管理工具
    ftpwho
    ftpwho显示当前连接到ftp服务器上的所有用户。这个命令菜单输出类似“/bin/ps”的输出,其格式为:
    <pid> <time> <tty> <connection details>
    其中<pid>表示ftp daemon用来处理这次文件传输的进程号,<time>表示用户什么时候连接到ftp服务器上,<tty>总是用问号(?)表示因为是通过ftp而不是telnet连接,<connection details>告诉连接是来自哪里、用户是谁以及用户现在在干什么。
    下面是ftpwho输出的一个例子:
    [root@deep]# ftpwho
   Service class openarch:
    5443 ? S 0:00 ftpd: win.openarch.com: admin: IDLE
    - 1 users ( 20 maximum)
    可以看到现在有一个用户登录(最多可以有20个用户同时登录),这个用户的用户名是admin来自win.openarch.com。
    ftpcount
    ftpcount是ftpwho的简化版,只显示登录到ftp服务器的用户数以及最多允许多少个用户登录。下面是一个例子:
    [root@deep]# ftpcount
    Service class openarch - 1 users ( 20 maximum) 本文作者:
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3