LoginSignup
1
2

More than 5 years have passed since last update.

proftpdでSFTPを受ける

Posted at

目的

下記目的のために、sshdではなくproftpdを使ってSFTPを受ける設定をします。

  • バーチャルユーザーを使いたい
  • ユーザーにSFTPはさせたいがコンソールとして使われたくない

設定内容

  • OSはCentOS7系
  • SFTPを受けるポートは8022番とする
  • バーチャルユーザーを専用パスワードファイルで設定する
    • ユーザ /etc/ftppasswd
    • グループ /etc/ftpgroup
  • バーチャルユーザーのホームディレクトリをROOTに見せる

手順

1.proftpdのインストール

CentOS7を前提にしますので、まずepelをインストールします

yum install epel-release

続いてproftpdのパッケージをインストールします

yum install proftpd proftpd-utils

2.設定変更

設定ファイルの変更内容です。

/etc/proftpd.conf
# 下記コメントアウト解除
LoadModule mod_sftp.c

# 下記どこか任意の場所に追加
<IfModule mod_sftp.c>
    <VirtualHost 0.0.0.0>
        SFTPEngine on
        SFTPLog /var/log/sftp.log
        DefaultRoot                     ~

        # バーチャルユーザーの設定
        AuthUserFile                    /etc/ftppasswd
        AuthGroupFile                   /etc/ftpgroup
        AuthOrder                       mod_auth_file.c

        Port 8022

        # hostkeyをsshdから流用する場合の設定
        SFTPHostKey /etc/ssh/ssh_host_rsa_key

        # CiphersとDigestsの設定
        # 脆弱性の状況を見て調整する項目
        SFTPCiphers aes256-ctr aes192-ctr aes128-ctr blowfish-ctr 
        SFTPDigests hmac-sha2-256 hmac-sha2-512 hmac-ripemd160
    </VirtualHost>
</IfModule>
  • SFTPの設定はVirtualHostでくくるのが重要です。くくらないとファイルのタイムスタンプ設定などで不具合が起きます。

hostkeyがそのままだとパーミッションエラーになるので、パーミッションを変更します。

chmod 600 /etc/ssh/ssh_host_rsa_key
  • パーミッション変更してもsshdの挙動に問題はありませんが、気になるようでしたらproftpd用に生成してもよいと思います。

3.バーチャルユーザー生成

バーチャルユーザー[contents]をUID:1001のユーザに紐付ける場合のコマンドラインです。
ホームディレクトリは[/var/www/site/contents]とします。

ftpasswd --passwd --file=/etc/ftppasswd --name=contents --uid=1001 --gid=1001 --home=/var/www/site/contents --shell=/bin/bash
ftpasswd --group --file=/etc/ftpgroup --name=contents --gid=1001

4.起動

systemctl start proftpd
systemctl enable proftpd

以上で完了です。
なお、firewalld等の設定は別途行ってください。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2