提供:すだちWiki
移動先: 案内検索

FTPサーバー構築(vsftpd)(CentOS7)

vsftpdインストール

[root@host3 ~]# yum -y install vsftpd ← vsftpdインストール

vsftpd設定

# Activate logging of uploads/downloads.
xferlog_enable=YES ← /var/log/vsftpd.logに接続・転送を記録(1/3)

# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log ← /var/log/vsftpd.logに接続・転送を記録(2/3)

# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=NO ← /var/log/vsftpd.logに接続・転送を記録(3/3)

# ASCII mangling is a horrible feature of the protocol.
ascii_upload_enable=YES ← アスキーモードでのアップロードを許可
ascii_download_enable=YES ← アスキーモードでのダウンロードを許可

# You may fully customise the login banner string:
ftpd_banner=Welcome to blah FTP service. ← FTPログイン時にソフト名とバージョンが表示されないようにする

# (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=YES ← デフォルトでホームディレクトリより上層へのアクセスを禁止する
chroot_list_enable=YES ← ホームディレクトリより上層へのアクセスを許可するユーザのリストの有効化
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list ← ホームディレクトリより上層へのアクセスを許可するユーザのリスト

# the presence of the "-R" option, so there is a strong case for enabling it.
ls_recurse_enable=YES ← ディレクトリごと削除できるようにする

# 以下を最下行へ追加
local_root=public_html ← ルートディレクトリ指定
use_localtime=YES ← タイムスタンプ時間を日本時間にする
ssl_enable=YES ← SSLの有効化
rsa_cert_file=/etc/pki/tls/certs/vsftpd.pem ← サーバー証明書を指定
force_local_logins_ssl=NO ← ログイン時にSSL接続を強制しない※暗号化しない接続もできるようにする場合のみ
force_local_data_ssl=NO ← データ転送時にSSL接続を強制しない※暗号化しない接続もできるようにする場合のみ

ホームディレクトリより上層へのアクセスを許可するユーザの登録

[root@host3 ~]# echo admin >> /etc/vsftpd/chroot_list
 ← 例としてユーザadminによるホームディレクトリより上層へのアクセスを許可する場合

ホームディレクトリより上層へのアクセスができないユーザのタイムスタンプを日本時間にする

新規ユーザ対処

[root@host3 ~]# mkdir /etc/skel/etc ← ユーザ登録時にホームディレクトリへetcディレクトリが作成されるようにする

[root@host3 ~]# cp /etc/localtime /etc/skel/etc/
 ← ユーザ登録時に/etc/localtimeがホームディレクトリのetcディレクトリへコピーされるようにする

既存ユーザ対処

[root@host3 ~]# vi localtimset ← localtimeセットアップスクリプト作成
#!/bin/bash

for user in `ls /home`
do
   id $user > /dev/null 2>&1
   if [ $? -eq 0 ]; then
        grep $user /etc/vsftpd/chroot_list > /dev/null 2>&1
        if [ $? -ne 0 ] && [ ! -f /home/$user/etc/localtime ]; then
            mkdir -p /home/$user/etc
            cp /etc/localtime /home/$user/etc
            echo $user
        fi
   fi
done

[root@host3 ~]# sh localtimset ← localtimeセットアップスクリプト実行
user1
・
・
・
usern

[root@host3 ~]# rm -f localtimset ← localtimeセットアップスクリプト削除

FTPサーバーへのアクセスを禁止するユーザの登録

[root@host3 ~]# echo admin >> /etc/vsftpd/ftpusers
 ← 例としてユーザadminによるFTPサーバーへのアクセスを禁止する場合

サーバー証明書作成

[root@host3 ~]# cd /etc/pki/tls/certs/ ← ディレクトリ移動

[root@host3 certs]# make vsftpd.pem ← サーバー証明書作成
umask 77 ; \
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
/usr/bin/openssl req -utf8 -newkey rsa:1024 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
cat $PEM1 >  vsftpd.pem ; \
echo ""    >> vsftpd.pem ; \
cat $PEM2 >> vsftpd.pem ; \
rm -f $PEM1 $PEM2
Generating a 1024 bit RSA private key
.................................++++++
................................++++++
writing new private key to '/tmp/openssl.OH7090'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:JP ← 国名応答
State or Province Name (full name) [Berkshire]:Tokushima ← 都道府県名応答
Locality Name (eg, city) [Newbury]:Tokushima ← 市区町村名応答
Organization Name (eg, company) [My Company Ltd]:sudachi.jp ← サイト名応答(なんでもいい)
Organizational Unit Name (eg, section) []: ← 空ENTER
Common Name (eg, your name or your server's hostname) []:ftp.sudachi.jp ← ホスト名応答
Email Address []:xxxxx@sudachi.jp ← 管理者メールアドレス応答

[root@host3 certs]# cd ← ホームディレクトリへ戻る

vsftpd起動

[root@host3 ~]# systemctl start vsftpd ← vsftpd起動

[root@host3 ~]# systemctl enable vsftpd ← vsftpd自動起動設定