proftp mysqlでユーザ管理(設定編)

10:14 pm FTP, FreeBSD

proftpdインストール編に続き、設定編です。mysqlでユーザー管理を行うことを念頭に設定を行います。設定はmysqlでデータベースを作成する所から行っていきましょう。あ、mysqlはすでに起動していることが条件です。

データベース名はproftpdで使用するので「proftpd」と名前を付けます。webサーバが複数存在して一台のデータベースサーバでアカウント管理を行う場合は「マシン名_proftpd」などわかりやすく、ルールを統一して規則正しく名前管理を管理していきましょうね。mysqlサーバはローカルホストにあると仮定して設定を行っていきます。

mysqlのテーブルとカラムは下記の通りです。

 usersテーブル

Field
Type
Null
Key
Default
Extra
userid
varchar(150)
 
PRI
   
passwd
varchar(30)
       
uid
smallint(5) unsigned
   
2000
 
gid
smallint(5) unsigned
   
2000
 
homedir
varchar(255)
YES
 
NULL
 
shell
varchar(255)
YES
 
/bin/sh
 

 

 groupsテーブル

Field
Type
Null
Key
Default
Extra
groupname
varchar(150)
 
PRI
   
gid
smallint(5) unsigned
 
UNI
2000
 
members
varchar(255)
YES
 
NULL
 

 

では、まずはmysqlにユーザ登録を行うこと所から始めます。「mysql -u root -p PASSWORD」でmysqlクライアントを起動してユーザ登録を行います。

 

mysql> grant select on proftpd.* to proftpd@localhost identified by ‘PASSWORD’;

mysql> flush privileges;

 

次にデータベースを作成していきます。データベース作成後、テーブルを作成していきます。

mysql> create database proftpd; 

mysql> use proftpd;

mysql>CREATE TABLE groups (
groupname varchar(150) NOT NULL,
gid smallint(5) unsigned DEFAULT ‘2000′ NOT NULL,
members varchar(255),
UNIQUE KEY gid (gid),
PRIMARY KEY (groupname)
);

mysql>CREATE TABLE users (
userid varchar(150) NOT NULL,
passwd varchar(30) NOT NULL,
uid smallint(5) unsigned DEFAULT ‘2000′ NOT NULL,
gid smallint(5) unsigned DEFAULT ‘2000′ NOT NULL,
homedir varchar(255),
shell varchar(255) DEFAULT ‘/bin/sh’,
PRIMARY KEY (userid)
);

 

このタイミングで専用のユーザーとグループを作成しましょう。わかりやすく[proftpd:proftpd]で作成することとします。

pw groupadd proftpd
pw useradd proftpd -g proftpd -d /nonexistent -s /nonexistent

 

最後に[/usr/local/etc/proftpd.conf]ファイルを編集します。自分は下記のような設定を行っています。設定内容はmysqlのアカウントでログインを可能にする、システムアカウントを保持しているユーザもログインを可能にする。またwheelユーザーは上位ディレクトリも参照可能、DNS Lookupを抑止、レジューム対応およびローカルタイムをしようするように設定しています。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#
# For more informations about Proftpd configuration
# look at : http://www.proftpd.org/
#
# This is a basic ProFTPD configuration file (rename it to
# ‘proftpd.conf’ for actual use.  It establishes a single server
# and a single anonymous login.  It assumes that you have a user/group
# “nobody” and “ftp” for normal operation and anon.

ServerName                      “ProFTPD”
ServerType                      standalone
DefaultServer                   on
ScoreboardFile          /var/run/proftpd.scoreboard

# Port 21 is the standard FTP port.
Port                            21

#DNS Lookupを抑止します。名前が引けないことによるログイン不全を解消する。
UseReverseDNS off
IdentLookups off

# Umask 022 is a good standard umask to prevent new dirs and files
# from being group and world writable.
Umask                           022

# To prevent DoS attacks, set the maximum number of child processes
# to 30.  If you need to allow more than 30 concurrent connections
# at once, simply increase this value.  Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd).
MaxInstances                    30

CommandBufferSize       512

# Set the user and group under which the server will run.
User                            proftpd
Group                           proftpd

#ディレクトリを表示する時の ls コマンドのオプションを指定します。
ListOptions                     “-a”

#wheel グループ以外はホームディレクトリより上に移動できないようにする。
DefaultRoot                     ~       !wheel

# To cause every FTP user to be “jailed” (chrooted) into their home
# directory, uncomment this line.
#DefaultRoot ~

# Normally, we want files to be overwriteable.
AllowOverwrite          on

#ローカルタイムの設定にする。
TimesGMT  FALSE

#クライアントが下記で設定した時間(秒)、何もしない場合接続を切る。
TimeoutIdle                     1200

#Resumeを有効にする
AllowStoreRestart on

#ログイン前に出てくるメッセージを”FTP Server ready.”に変更する。
ServerIdent                     on      “FTP Server ready.”
# Bar use of SITE CHMOD by default
#<Limit SITE_CHMOD>
#  DenyAll
#</Limit>

# MySQLの接続先とユーザID及びPASSWORDの設定
SQLConnectInfo proftpd@localhost proftpd PASSWORD
SQLUserInfo users userid passwd uid gid homedir shell
SQLGroupInfo groups groupname gid members
SQLAuthenticate on

# SQLAuthTypesをBackendにするとMySQLのPASSWORD関数で暗号化される
SQLAuthTypes Plaintext
# A basic anonymous configuration, no upload directories.  If you do not
# want anonymous users, simply delete this entire <Anonymous> section.

#########################################################################
#                                                                       #
# Uncomment lines with only one # to allow basic anonymous access       #
#                                                                       #
#########################################################################

#<Anonymous ~ftp>
#   User                                ftp
#   Group                               ftp

  ### We want clients to be able to login with “anonymous” as well as “ftp”
  # UserAlias                   anonymous ftp

  ### Limit the maximum number of anonymous logins
  # MaxClients                  10

  ### We want ‘welcome.msg’ displayed at login, and ‘.message’ displayed
  ### in each newly chdired directory.
  # DisplayLogin                        welcome.msg
  # DisplayFirstChdir           .message

  ### Limit WRITE everywhere in the anonymous chroot
  # <Limit WRITE>
  #   DenyAll
  # </Limit>
#</Anonymous>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

以上で設定は完了です。実際にmysqlで仮想ユーザーを追加する場合は

insert into users set userid = “USERID”,passwd = “PASSWORD”,homedir =”HOMEDIR”;

insert into groups set groupname = “GROUPNAME”,members = “MAILAADRESS”;

でユーザーとグループを追加します。

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.