ubuntuの下でFTPサーバーを構築する


最近からwordpressで自分のブログを作り始め、wordpressを自動的に更新する際にFTPサービスを利用し、Ubuntuのクラウドホスト上にFTPを配置するのに時間がかかったので、ここでまとめてみます.
FTPを構築するには、有名なvsftpdを使うに違いない.具体的な手順は次のとおりです.
  • インストールvsftpd
    apt-get install vsftpd
  • 構成vsftpdパラメータプロファイルは/etc/vsftpd.confであり、まず元のプロファイルをバックアップします.
    cp /etc/vsftpd.conf /etc/vsftpd.conf.old
    その後、パラメータを変更します.
    # Example config file /etc/vsftpd.conf
    listen=YES
    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の3つのパラメータは、以下のように説明されています.
    # 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であれば、ローカルアカウントはホームディレクトリ以外の他のディレクトリにアクセスすることができ、このときchroot_list_filechroot()ができないユーザである.chroot_local_userYESである場合、ローカルアカウントは自分のディレクトリにしかアクセスできず、chroot_list_filechroot()可能なユーザーリストとなる.
  • 上記が完了したら、/etc/shellsファイルを編集し、/sbin/nologinがなければ、この行を追加します.
    /sbin/nologin
  • 加入者
    useradd -g ftp -d /home/username -m username
    #-g          
    #-d          
    #-m     
    passwd username #       
  • 上記の手順のみを実行すると、wordpressでftp更新を使用すると、新規ユーザーにwordpressが存在するディレクトリの変更権限がないため、ユーザーの権限を変更する必要があるため、ディレクトリを作成できないエラーが発生します.(ここwordpressのディレクトリは/var/www/html/wordpress)
    chmod -R 755 /var/www/html/wordpress
    chown -R username:ftp /www/html/wordpress
  • vsftpdサービス
    service vsftpd restart
    を再起動するとftpを使用してwordpressの更新を行うことができ、新しい翻訳、テーマ、プラグインをインストールすることもできます.

  • 参考資料
    vsftpdインストールFTPユーザーディレクトリ権限構成