FTPサーバを立ててchrootする要件があったので久しぶりにvsftpなどを触りました。。
そのメモ
要件
・FTP接続(パッシブモード)
・chrootする(場所は他ユーザーのホームディレクトリ配下のフォルダ)
・OSはcentOS 6.9
構築
FTPの構築
yum -y install vsftpd service vsftpd start chkconfig vsftpd on
FTPユーザ作成
useradd user1 -u 600 -g 1000 passwd user1
作成ユーザーのグループIDはchrootディレクトリと同じにする
FTPコンフィグの修正
以下差分どん
# Example config file /etc/vsftpd/vsftpd.conf # Example config file /etc/vsftpd/vsftpd.conf # # # The default compiled in settings are fairly paranoid. This # The default compiled in settings are fairly paranoid. This # loosens things up a bit, to make the ftp daemon more usable # loosens things up a bit, to make the ftp daemon more usable # Please see vsftpd.conf.5 for all compiled in defaults. # Please see vsftpd.conf.5 for all compiled in defaults. # # # READ THIS: This example file is NOT an exhaustive list of v # READ THIS: This example file is NOT an exhaustive list of v # Please read the vsftpd.conf.5 manual page to get a full ide # Please read the vsftpd.conf.5 manual page to get a full ide # capabilities. # capabilities. # # # Allow anonymous FTP? (Beware - allowed by default if you co # Allow anonymous FTP? (Beware - allowed by default if you co anonymous_enable=NO | anonymous_enable=YES # # # Uncomment this to allow local users to log in. # Uncomment this to allow local users to log in. local_enable=YES local_enable=YES # # # Uncomment this to enable any form of FTP write command. # Uncomment this to enable any form of FTP write command. write_enable=YES write_enable=YES # # # Default umask for local users is 077. You may wish to chang # Default umask for local users is 077. You may wish to chang # if your users expect that (022 is used by most other ftpd's # if your users expect that (022 is used by most other ftpd's local_umask=022 local_umask=022 # # # Uncomment this to allow the anonymous FTP user to upload fi # Uncomment this to allow the anonymous FTP user to upload fi # has an effect if the above global write enable is activated # has an effect if the above global write enable is activated # obviously need to create a directory writable by the FTP us # obviously need to create a directory writable by the FTP us #anon_upload_enable=YES #anon_upload_enable=YES # # # Uncomment this if you want the anonymous FTP user to be abl # Uncomment this if you want the anonymous FTP user to be abl # new directories. # new directories. #anon_mkdir_write_enable=YES #anon_mkdir_write_enable=YES # # # Activate directory messages - messages given to remote user # Activate directory messages - messages given to remote user # go into a certain directory. # go into a certain directory. dirmessage_enable=YES dirmessage_enable=YES # # # The target log file can be vsftpd_log_file or xferlog_file. # The target log file can be vsftpd_log_file or xferlog_file. # This depends on setting xferlog_std_format parameter # This depends on setting xferlog_std_format parameter xferlog_enable=YES xferlog_enable=YES # # # Make sure PORT transfer connections originate from port 20 # Make sure PORT transfer connections originate from port 20 connect_from_port_20=NO | connect_from_port_20=YES # # # If you want, you can arrange for uploaded anonymous files t # If you want, you can arrange for uploaded anonymous files t # a different user. Note! Using "root" for uploaded files is # a different user. Note! Using "root" for uploaded files is # recommended! # recommended! #chown_uploads=YES #chown_uploads=YES #chown_username=whoever #chown_username=whoever # # # The name of log file when xferlog_enable=YES and xferlog_st # The name of log file when xferlog_enable=YES and xferlog_st # WARNING - changing this filename affects /etc/logrotate.d/v # WARNING - changing this filename affects /etc/logrotate.d/v #xferlog_file=/var/log/xferlog #xferlog_file=/var/log/xferlog # # # Switches between logging into vsftpd_log_file and xferlog_f # Switches between logging into vsftpd_log_file and xferlog_f # NO writes to vsftpd_log_file, YES to xferlog_file # NO writes to vsftpd_log_file, YES to xferlog_file xferlog_std_format=YES xferlog_std_format=YES # # # You may change the default value for timing out an idle ses # You may change the default value for timing out an idle ses #idle_session_timeout=600 #idle_session_timeout=600 # # # You may change the default value for timing out a data conn # You may change the default value for timing out a data conn #data_connection_timeout=120 #data_connection_timeout=120 # # # It is recommended that you define on your system a unique u # It is recommended that you define on your system a unique u # ftp server can use as a totally isolated and unprivileged u # ftp server can use as a totally isolated and unprivileged u #nopriv_user=ftpsecure #nopriv_user=ftpsecure # # # Enable this and the server will recognise asynchronous ABOR # Enable this and the server will recognise asynchronous ABOR # recommended for security (the code is non-trivial). Not ena # recommended for security (the code is non-trivial). Not ena # however, may confuse older FTP clients. # however, may confuse older FTP clients. #async_abor_enable=YES #async_abor_enable=YES # # # By default the server will pretend to allow ASCII mode but # By default the server will pretend to allow ASCII mode but # the request. Turn on the below options to have the server a # the request. Turn on the below options to have the server a # mangling on files when in ASCII mode. # mangling on files when in ASCII mode. # Beware that on some FTP servers, ASCII support allows a den # Beware that on some FTP servers, ASCII support allows a den # attack (DoS) via the command "SIZE /big/file" in ASCII mode # attack (DoS) via the command "SIZE /big/file" in ASCII mode # predicted this attack and has always been safe, reporting t # predicted this attack and has always been safe, reporting t # raw file. # raw file. # ASCII mangling is a horrible feature of the protocol. # ASCII mangling is a horrible feature of the protocol. #ascii_upload_enable=YES #ascii_upload_enable=YES #ascii_download_enable=YES #ascii_download_enable=YES # # # You may fully customise the login banner string: # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. #ftpd_banner=Welcome to blah FTP service. # # # You may specify a file of disallowed anonymous e-mail addre # You may specify a file of disallowed anonymous e-mail addre # useful for combatting certain DoS attacks. # useful for combatting certain DoS attacks. #deny_email_enable=YES #deny_email_enable=YES # (default follows) # (default follows) #banned_email_file=/etc/vsftpd/banned_emails #banned_email_file=/etc/vsftpd/banned_emails # # # You may specify an explicit list of local users to chroot() # You may specify an explicit list of local users to chroot() # directory. If chroot_local_user is YES, then this list beco # directory. If chroot_local_user is YES, then this list beco # users to NOT chroot(). # users to NOT chroot(). chroot_local_user=YES | #chroot_local_user=YES chroot_list_enable=YES | #chroot_list_enable=YES # (default follows) # (default follows) chroot_list_file=/etc/vsftpd/chroot_list | #chroot_list_file=/etc/vsftpd/chroot_list # # # You may activate the "-R" option to the builtin ls. This is # You may activate the "-R" option to the builtin ls. This is # default to avoid remote users being able to cause excessive # default to avoid remote users being able to cause excessive # sites. However, some broken FTP clients such as "ncftp" and # sites. However, some broken FTP clients such as "ncftp" and # the presence of the "-R" option, so there is a strong case # the presence of the "-R" option, so there is a strong case #ls_recurse_enable=YES #ls_recurse_enable=YES # # # When "listen" directive is enabled, vsftpd runs in standalo # When "listen" directive is enabled, vsftpd runs in standalo # listens on IPv4 sockets. This directive cannot be used in c # listens on IPv4 sockets. This directive cannot be used in c # with the listen_ipv6 directive. # with the listen_ipv6 directive. listen=YES listen=YES # # # This directive enables listening on IPv6 sockets. To listen # This directive enables listening on IPv6 sockets. To listen # sockets, you must run two copies of vsftpd with two configu # sockets, you must run two copies of vsftpd with two configu # Make sure, that one of the listen options is commented !! # Make sure, that one of the listen options is commented !! #listen_ipv6=YES #listen_ipv6=YES pam_service_name=vsftpd pam_service_name=vsftpd userlist_enable=YES userlist_enable=YES tcp_wrappers=YES tcp_wrappers=YES userlist_deny=NO < userlist_file=/etc/vsftpd/user_list < pasv_enable=YES < pasv_min_port=30000 < pasv_max_port=30100 < user_config_dir=/etc/vsftpd/user_config_dir <
その他リストとか作成
cat 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 even prompt for a password. # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers # for users that are denied. user1
cat ftpusers
# Users that are not allowed to login via ftp root bin daemon adm lp sync shutdown halt mail news uucp operator games nobody
touch chroot_list
中身不要
mkdir user_config_dir vi user_config_dir/user1
local_root=/home/otheruser/path/to/chroot_dir
chroot_dirの権限を変更
chmod 770 /home/otheruser/path/to/chroot_dir
vsftpを再起動して反映
まとめ
昨今FTPの構築なんてなかなかしないので忘れますね。
権限周りはいろいろややこしかったです。
FTPのコンフィグもyes/noの組み合わせで設定の内容が変わったりするのでここも難敵です。
とりあえず弊社でよくあるパターンは上記で補えます。
以上