歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> 用Linux架設FTP服務器(5)

用Linux架設FTP服務器(5)

日期:2017/3/2 16:56:33   编辑:Linux服務器
 配置“/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 © Linux教程網 All Rights Reserved