LinuxでFTPサーバ(vsftp)




RedHat8でFTPサーバを構築する。
今回は、RedHat8に付属しているvsftpを使用する。

vsftpd ver 1.1.0

○設定方針
1.匿名ログインを拒否
2.ユーザに特定のディレクトリしか触らせない
3.rootユーザでのアクセス拒否

○デフォルトからの設定変更箇所
変更するファイル:/etc/vsftpd.conf
==================
1.の対応
==================
匿名(anonymous)ログインを拒否する。
変更前:anonymous_enable=YES
  ↓
変更後:anonymous_enable=NO

==================
2.の対応
==================
chrootを有効にすることで、
ユーザにホームディレクトリ以外にアクセスさせないようにする。
変更前:#chroot_list_enable=NO
  ↓
変更後:chroot_list_enable=YES

これでchrootが有効になったが、これだけではユーザには適用されない。
適用したいユーザを「/etc/vsftpd.chroot_list」に記載する。
ftpuser1
ftpuser2
単純にユーザ名を列記すれば良い。
反映にvsftpdの再起動は不要。

この設定で実際の動きを見てみると、
ftpuser1でログインした場合
ftp> pwd
257 "/" ←実際は"/home/ftpuser1"
ftp> cd ../
250 Directory successfully changed
ftp> pwd
257 "/"
/home/ftpuser1がルートディレクトリに見え、
その上位へのチェンジディレクトリはできない。

ftpuser3でログインした場合
ftp> pwd
257 "/home/ftpuser3"
ftp> cd ../
250 Directory successfully changed
ftp> pwd
257 "/home"
/home/ftpuser3の上位の/homeへチェンジディレクトリできてしまう。

==================
3.の対応
==================
特定のユーザ以外のrootユーザなどのログインを拒否する。

拒否したいユーザを「/etc/vsftpd.ftpusers」に記載する。
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
このファイルに列記したユーザによるFTPのログインを拒否する。
デフォルトでrootユーザのログインは拒否するようになっている。
反映にvsftpdの再起動は不要。

==================
補足1
==================
明示的にFTPのログインを拒否したい場合の設定(パスワードのプロンプトも返さない)

/etc/vsftpd.conf
userlist_deny=YES (デフォルト:記載無し)
userlist_enable=YES (追記する)

これで「/etc/vsftpd.user_list」に記載しているユーザのログインを拒否する
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file.
# If userlist_deny=YES (default), never allow users in this file, and
# do not ever prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd.ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
ftpuser3

実際の動作を見てみると、
[root@test01 etc]# ftp localhost
Connected to localhost (127.0.0.1)
220 ready, due (vsFTPd 1.1.0: beat me, break me)
Name (localhost:root): ftpuser3
530 Permission denied.
Login failed.
ftp>
パスワードのプロンプトも出さずに拒否している。

==================
補足2
==================
FTPのログインを許可するユーザを明示的に指定したい場合の設定

/etc/vsftpd.conf
userlist_deny=NO (追記する)
userlist_enable=YES (追記する)

これで「/etc/vsftpd.user_list」に記載しているユーザのログインだけを許可する
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file.
# If userlist_deny=YES (default), never allow users in this file, and
# do not ever prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd.ftpusers
# for users that are denied.
#root
#bin
#daemon
#adm
#lp
#sync
#shutdown
#halt
#mail
#news
#uucp
#operator
#games
#nobody
ftpuser3