ubuntu下搭建FTP服務器

最近開始用wordpress搭建本身的我的博客,在自動更新wordpress的時候要用到FTP服務,在Ubuntu的雲主機上配置FTP花費了很多時間,在這裏做一下總結。html

搭建FTP確定是要用大名鼎鼎的vsftpd。具體步驟以下:shell

  1. 安裝vsftpdbash

    apt-get install vsftpd
  2. 配置vsftpd參數
    配置文件是/etc/vsftpd.conf,首先先備份原配置文件。wordpress

    cp /etc/vsftpd.conf /etc/vsftpd.conf.old

    而後修改其中的參數,以下:this

    # Example config file /etc/vsftpd.conf
    listen=YES<br>anonymous_enable=NO #禁止匿名登陸
    local_enable=YES #本地用戶能夠登陸
    write_enable=YES #容許寫操做,包括上傳,修改等
    # Activate directory messages - messages given to remote users when they
    # go into a certain directory.
    dirmessage_enable=YES #顯示目錄信息
    use_localtime=YES #使用本地時間
    xferlog_enable=YES #開啓日誌
    xferlog_file=/var/log/vsftpd.log #日誌存儲位置
    xferlog_std_format=YES #日誌標準格式
    chroot_local_user=YES #將用戶限制在他們的home目錄
    chroot_list_enable=YES #啓用能夠chroot的用戶的列表
    chroot_list_file=/etc/vsftpd.chroot_list #指定能夠chroot的用戶列表的位置
    ls_recurse_enable=YES #容許遞歸操做
    secure_chroot_dir=/var/run/vsftpd/empty #必須爲空

    關於chroot_local_user,chroot_list_enable,chroot_list_flie三個參數,有以下解釋。插件

    # You may restrict local users to their home directories.  See the FAQ for
    # the possible risks in this before using chroot_local_user or
    # chroot_list_enable below.
    #
    # You may specify an explicit list of local users to chroot() to their home
    # directory. If chroot_local_user is YES, then this list becomes a list of
    # users to NOT chroot().
    # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
    # the user does not have write access to the top level directory within the
    # chroot)

    也就是說,若是chroot_local_user選項爲NO,則本地帳戶能夠訪問除home目錄之外的其餘目錄,此時chroot_list_file是不能夠chroot()的用戶;當chroot_local_userYES時,本地帳戶只能訪問自家目錄,此時chroot_list_file變成能夠chroot()的用戶列表。翻譯

  3. 完成上面這些以後,編輯/etc/shells文件,若是沒有/sbin/nologin,要添加這一行。rest

    /sbin/nologin
  4. 添加用戶日誌

    useradd -g ftp -d /home/username -m username
    #-g選項指明用戶所在的組
    #-d選項指明用戶的家目錄
    #-m指明用戶名
    passwd username #給用戶設置密碼
  5. 若是隻執行完上述步驟,在wordpress中使用ftp更新時仍然會遇到沒法建立目錄的錯誤,緣由是新建的用戶並無wordpress所在目錄的修改權限,因此要修改用戶的權限。(我這裏wordpress所在的目錄是/var/www/html/wordpresscode

    chmod -R 755 /var/www/html/wordpress
    chown -R username:ftp /www/html/wordpress
  6. 重啓vsftpd服務

    service vsftpd restart

    而後就可使用ftp進行wordpress的更新了,也能夠安裝新的翻譯,主題,插件。

參考資料

vsftpd安裝
FTP用戶目錄權限配置

相關文章
相關標籤/搜索