ubuntuに vsftpdをインストール(chroot_list_fileとuserlist_fileによるアクセス管理方法の整理)

投稿者: | 2021/02/23

ubuntu 20.04に vsftpdをインストールする

vsftpdの設定ファイル

FTPサーバーである vsftpdをインストールする際に、毎回同じところで躓くので、メモに残しておく。

vsftpdのインストールそのものは次の 2行で終了。

sudo apt update
sudo apt-get install vsftpd

設定ファイルである vsftpd.confのバックアップを取って、いざ編集スタート。

sudo mv -v /etc/vsftpd.conf /etc/vsftpd.conf.bk
sudo nano /etc/vsftpd.conf

vsftpd.confの中身からコメントや説明を抜き取ったデフォルトパラメータは次の通り。
実際にはこれ以外のパラメータも存在するし、不要なものもある。

ハイライトされている行が有効なパラメータで、それ以外はコメントアウトされている。
で、実際デフォルトの設定で動作するかと言うと、まともには動いてはくれない……

#Example config file /etc/vsftpd.conf
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
#local_umask=022
#anon_upload_enable=YES
#anon_mkdir_write_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
#chown_uploads=YES
#chown_username=whoever
#xferlog_file=/var/log/vsftpd.log
#xferlog_std_format=YES
#idle_session_timeout=600
#data_connection_timeout=120
#nopriv_user=ftpsecure
#async_abor_enable=YES
#ascii_upload_enable=YES
#ascii_download_enable=YES
#ftpd_banner=Welcome to blah FTP service.
#deny_email_enable=YES
#banned_email_file=/etc/vsftpd.banned_emails
#chroot_local_user=YES
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd.chroot_list
#ls_recurse_enable=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
#utf8_filesystem=YES

chroot_listと user_listの解釈と設定の仕方

迷子になるのは、いつも chroot_list_fileと userlist_fileに記載したユーザーのアクセス権限の行方。
毎回、manを確認しに行く。

man vsftpd.conf

chroot_list_fileに載せたユーザーのアクセス権限

chroot_listに関係するパラメータは次の 3つ。

  • chroot_list_enable
  • chroot_local_user
  • chroot_list_file

chroot_list_enable
If activated, you may provide a list of local users who are placed in a chroot() jail in their home directory upon login.The meaning is slightly different if chroot_local_user is set to YES. In this case, the list becomes a list of users which are NOT to be placed in a chroot() jail. By default, the file containing this list is /etc/vsftpd.chroot_list, but you may override this with the chroot_list_file setting.
Default: NO


chroot_local_user
If set to YES, local users will be (by default) placed in a chroot() jail in their home directory after login. Warning: This option has security implications, especially if the users have upload permission, or shell access. Only enable if you know what you are doing. Note that these security implications are not vsftpd specific. They apply to all FTP daemons which offer to put local users in chroot() jails.
Default: NO


chroot_list_file
The option is the name of a file containing a list of local users which will be placed in a chroot() jail in their home directory. This option is only relevant if the option chroot_list_enable is enabled. If the option chroot_local_user is enabled, then the list file becomes a list of users to NOT place in a chroot() jail.
Default: /etc/vsftpd.chroot_list

chroot_list_enableパラメータの解釈

YESに設定した場合、ログイン後にホームディレクトリへと chroot()されるローカルユーザのリストが有効になる。
次の項目の chroot_local_userを YESに設定した場合には、リストは chroot() jailされないユーザ のリストとなる。

※ホームディレクトリへとchroot() jailされたユーザーは、ホームディレクトリより上層にアクセスできない。

chroot_local_userパラメータの解釈

chroot_list_enableが YESに設定したときに動作する。
YESに設定した場合、ローカルユーザはログイン後、ホームディレクトリへと chroot()される。
ただし、次の chroot_list_fileにリストアップされたユーザーは除外される。

chroot_list_fileパラメータの解釈

chroot_list_enable が有効であることが前提に動作する。
ホームディレクトリ内に choot() jailされるローカルユーザのリストを示すファイル名を指定する。
chroot_local_user が有効であれば、隔離除外リストとなる。

chroot_list設定例と動作

例として、vsftpd.chroot_listに aaaと bbbユーザーを登録。
さらに、local_rootパラメータに、/var/www/を設定。

$ sudo nano /etc/vsftpd.chroot_list
aaa
bbb
sudo nano /etc/vsftpd.conf
…
local_root=/var/www/
…

次のように設定した場合、

  • chroot_local_user=YES
  • chroot_list_enable=YES
  • chroot_list_file=/etc/vsftpd.chroot_list

aaaと bbbユーザーは、ログイン後に /var/www/に移動し、/var/www/より上層にもアクセス可能。

リストに載っていない、例えば cccユーザーは、/var/www/より上層にもアクセスできない。

次のように設定した場合、

  • chroot_local_user=YES
  • chroot_list_enable=NO
  • chroot_list_file=/etc/vsftpd.chroot_list

aaaと bbbユーザーは、ログイン後に /var/www/に移動し、/var/www/より上層にはアクセスできない。

リストに載っていない、例えば cccユーザーは、/var/www/より上層にもアクセス可能。

userlist_fileに載せたユーザーのアクセス権限

userlistに関係するパラメータは次の 3つ。

  • userlist_enable
  • userlist_deny
  • userlist_file

userlist_enable
If enabled, vsftpd will load a list of usernames, from the filename given by userlist_file. If a user tries to log in using a name in this file, they will be denied before they are asked for a password. This may be useful in preventing cleartext passwords being transmitted. See also userlist_deny.
Default: NO


userlist_deny
This option is examined if userlist_enable is activated. If you set this setting to NO, then users will be denied login unless they are explicitly listed in the file specified by userlist_file. When login is denied, the denial is issued be fore the user is asked for a password.
Default: YES


userlist_file
This option is the name of the file loaded when the userlist_enable option is active.
Default: /etc/vsftpd.user_list

userlist_enablerパラメータの解釈

YESに設定した場合、userlist_file で指定したファイルをユーザ名のリストとして読み込まれる。

userlist_denyパラメータの解釈

userlist_enable が YESの場合のみ動作する。
NOにした場合、 userlist_fileで指定したファイルにリストされたユーザ以外はログインが拒否される。

YESにした場合、userlist_fileで指定したファイルにリストされたユーザのログインが拒否される。

userlist_fileパラメータの解釈

userlist_enableが YESの場合読み込まれ、読み込まれるファイルの ファイル名を指定する。

userlist設定例と動作

例として、vsftpd.user_listに aaaと bbbユーザーを登録。

$ sudo nano /etc/vsftpd.user_list
aaa
bbb

次のように設定した場合、

  • userlist_enable=YES
  • userlist_deny=YES
  • userlist_file=/etc/vsftpd.user_list

リストに含まれる aaa及び bbbユーザーは FTPによる接続を拒否される。

次のように設定した場合、

  • userlist_enable=YES
  • userlist_deny=NO
  • userlist_file=/etc/vsftpd.user_list

リストに含まれる aaa及び bbbユーザーは FTPによる接続を許可される。

vsftpd.confの必要最小限設定

外部へ公開せず、家の中だけで使用するのであれば、必要かつ最小限の以下の設定で問題ないはず。

$ sudo nano /etc/vsftpd.conf

listen=YES
listen_ipv6=NO
connect_from_port_20=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
ls_recurse_enable=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=41000
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO
local_root=/var/www/

※/var/www/より上層にもアクセス可能に設定してます。

各行の説明
項目 初期値 説明 設定値
listen NO スタンドアロンモードで起動 YES
listen_ipv6 NO IPv4ソケットの代わりにIPv6ソケットを待ち受ける(listenと排他) NO
connect_
from_port_20
YES Activeモード時のデータコネクションポートを20番に固定する NO
anonymous_
enable
YES anonymous(匿名)ユーザによるアクセス拒否する NO
local_enable NO ローカルユーザのログインを許可する(YESの場合/etc/passwd にあるユーザアカウントを使う) YES
write_enable NO すべてのFTPコマンドを許可 YES
chroot_
local_user
NO 設定したディレクトリより上層への移動を禁止する YES
chroot_
list_enable
NO chroot管理対象ユーザーリストを有効にする YES
chroot_
list_file
/etc/vsftpd.chroot_list chrootの対象ユーザーのリストファイルの場所を指定する /etc/vsftpd.chroot_list
ls_
recurse_enable
NO サブフォルダを含む一括転送を許可する YES
secure_
chroot_dir
/var/run/vsftpd/empty ファイルアクセスを要求しないときに使用するディレクトリを指定する /var/run/vsftpd/empty
pam_
service_name
vsftpd vsftpd が使用する PAM サービス名を指定する vsftpd
pasv_enable YES パッシブモードを有効化する YES
pasv_min_port 0 パッシブモードデータ接続に割り当てるポートの最小値を指定する 40000
pasv_max_port 0 パッシブモードデータ接続に割り当てるポートの最大値を指定する 41000
userlist_enable NO ユーザ名のリストとしてuserlist_fileで指定したファイルを有効にする YES
userlist_file /etc/vsftpd.user_list パッシブモードデータ接続に割り当てるポートの最大値を指定する /etc/vsftpd.user_list
userlist_deny YES NOにした場合、userlist_fileで指定したファイルにリストされたユーザ以外はログインを拒否する NO
local_root ログイン後に移動させるディレクトリを指定する /var/www/






コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です