AlmaLinux 9 に FTP サーバーを構築する機会があり、vsftpd で設定したがうまくいかず、結局 ProFTPD にしたという話。
環境
- OS:AlmaLinux release 9.4 (Seafoam Ocelot)
- FTPd:vsftpd(version 3.0.5)⇒ ProFTPD(Version 1.3.8b)
- 暗号化モード:TLS 1.2、Implicit
- クライアント:NextFTP4(Ver4.95.00 / 64bit)
vsftpd の設定
CentOS 7 からの移行だったので、以前の環境から使用していた vsftpd をインストールしました。
Let's Encrypt で取得した SSL 証明書を使って FTPS(Implicit モード)を設定します。
vsftpd の設定(SSL 周りを抜粋)は下記のとおりです。
# DEBUG
debug_ssl=yes
log_ftp_protocol=yes
# SSL
ssl_enable=YES
ssl_sslv2=NO
ssl_sslv3=NO
ssl_tlsv1=NO
ssl_tlsv1_1=NO
ssl_tlsv1_2=YES
ssl_ciphers=HIGH
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
rsa_cert_file=/etc/letsencrypt/live/ドメイン名/fullchain.pem
rsa_private_key_file=/etc/letsencrypt/live/ドメイン名/privkey.pem
require_ssl_reuse=NO
#strict_ssl_read_eof=NO
#strict_ssl_write_shutdown=NO
# Implicit
implicit_ssl=YES
listen_port=990
# PASV
pasv_enable=YES
pasv_address=xxx.xxx.xxx.xxx
pasv_min_port=60000
pasv_max_port=60100NextFTP クライアントから接続すると、問題なく接続できます。ところがファイルをアップロードしていると止まってしまう場合があり、サーバー上に 0 バイトのファイルが作られた状態でエラーになります。
DEBUG: Client "xxx.xxx.xxx.xxx", "SSL version: TLSv1.3, SSL cipher: TLS_AES_256_GCM_SHA384, not reused, no cert"
DEBUG: Client "xxx.xxx.xxx.xxx", "SSL shutdown state is: NONE"
DEBUG: Client "xxx.xxx.xxx.xxx", "SSL shutdown state is: SSL_SENT_SHUTDOWN"
DEBUG: Client "xxx.xxx.xxx.xxx", "SSL ret: 18446744073709551615, SSL error: error:00000000:lib(0)::reason(0), errno: 32"
FTP response: Client "xxx.xxx.xxx.xxx", "426 Failure reading network stream."
FAIL UPLOAD: Client "xxx.xxx.xxx.xxx", "/xxxxxxxxxxx/test.cgi", 0.00Kbyte/secエラーログを見ると、SSL 関連のエラーが出ています。
strict_ssl_read_eof の値を変えたり、ssl_ciphers の設定を色々弄ってみたのですが、どれもうまくいかず結局 ProFTPD に乗り換えることにしました。
ProFTPD の設定
ProFTPD の設定は不慣れなため Include /etc/proftpd/conf.d/*.conf でオーバーライドせずに、proftpd.conf にすべてベタ書きしました。
ログインするユーザーは 1 人だけで、Web サイト(/var/www/html)の更新ができれば良いという事なので、MySQL でのアカウント管理なども連携していません。
# Load DSO modules as required
Include /etc/proftpd/modules.conf
# サーバー名
ServerName "サーバー名"
ServerIdent off
MasqueradeAddress ドメイン名
ServerAdmin メールアドレス
# IPv6 設定
UseIPv6 off
# 認証ポート
Port 990
# パッシブポート
MasqueradeAddress xxx.xxx.xxx.xxx
PassivePorts 60000 60100
# 逆引き DNS を抑止
UseReverseDNS off
# プロセス数
MaxInstances 10
MaxClientsPerHost 10
# リジューム
AllowStoreRestart on
AllowRetrieveRestart on
# アップロード失敗時自動削除
DeleteAbortedStores on
# ユーザーの設定
RootLogin off
# タイムアウト
TimeoutIdle 600
TimeoutNoTransfer 600
TimeoutStalled 3600
# Umask設定
Umask 022
CreateHome on dirmode 755
# ユーザーとグループ設定
User ユーザー名
Group グループ名
# ログインユーザーの制限
<Limit LOGIN>
AllowGroup ユーザー名
DenyAll
</Limit>
# ディレクトリ設定
DefaultRoot /var/www
DefaultChdir /var/www/html グループ名
# ファイルの上書きを許可
<Directory />
AllowOverwrite on
</Directory>
# ドットで始まるファイルを表示
ListOptions "-a"
# ローカルタイム設定
TimesGMT off
# ログ
SystemLog /var/log/proftpd/proftpd.log
LogFormat default "%h %l %u %t \"%r\" %s %b"
ExtendedLog /var/log/proftpd/access.log WRITE,READ default
LogFormat auth "%v [%P] %h %t \"%r\" %s"
ExtendedLog /var/log/proftpd/auth.log AUTH auth
TransferLog /var/log/proftpd/xfer.log
# SSL の設定
<IfModule mod_tls.c>
TLSEngine on
TLSRequired on
TLSVerifyClient off
TLSRSACertificateFile /etc/letsencrypt/live/ドメイン名/cert.pem
TLSRSACertificateKeyFile /etc/letsencrypt/live/ドメイン名/privkey.pem
TLSCACertificateFile /etc/letsencrypt/live/ドメイン名/chain.pem
TLSProtocol TLSv1.2
TLSCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
TLSOptions NoSessionReuseRequired UseImplicitSSL
</IfModule>Implicit にするために TLSOptions に UseImplicitSSL を追加し、Port を 990 にしています。
この他にも /etc/ftpusers を編集してログインしないユーザーを追記しておきました。
クライアント(NextFTP)でアクセスして、当該ファイルを含めて問題なくアップロードできる事を確認しました。
まとめ
FTP が不調の間 SFTP を使用してもらいましたが、WinSCP の転送設定が適切でなかったため Perl の CGI ファイルがバイナリモードで転送されてしまい、Internal Server Error になってしまいました。
とはいえ、サーバー側(sshd_config)で chroot の設定と、クライアント側(WinSCP)でテキストモード転送の設定をちゃんとすれば、FTP を使わず SFTP で代用可能なケースも多いかもしれません。


コメント