FTPサーバーのインストール


参考サイト
http://www.suzaku-cs.com/~gai/proftpd.html

proftpdのインストール

pakagesからインストールする場合は、pkg_addでインストールしてください。

hoge# pkg_add proftpd-1.2.8.tar.gz

ソースファイルの展開
ここでは、ソースファイルからインストールします。
下記のサイトからソースファイルをとってきて、展開してmakeします。
以下のようにしてインストールしました。

hoge# cd /usr/local/src
hoge# tar zxvf proftpd-1.2.6rc2.tar.gz
hoge# cd proftpd-1.2.6rc2
hoge# ./configure --prefix=/usr/local/proftpd
hoge# make

hoge# make install

/etc/pam.confの編集
ftp auth    required   pam_unix.so   try_first_pass
ftp account required   pam_unix.so   try_first_pass
ftp session required   pam_permit.so

設定ファイルの編集
/usr/local/proftpd/etc/proftpd.confの設定ファイルを開いて、エデイタ で編集します。
anonymaus ftp接続を許可しない場合は、以下のような感じになります。
# 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			"ホスト&サーバードメイン"
ServerType			standalone
ServerAdmin			"管理者のメールアドレス"
DefaultServer			on

# Port 21 is the standard FTP port.
Port				21
# 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

# Set the user and group that the server normally runs at.
User				nobody
Group				nogroup

# Normally, we want files to be overwriteable.
<Directory /*>
  AllowOverwrite		on
</Directory>

DefaultRoot	~	!wheel



■ServerName
オープニングメッセージに表示されるサーバー名
■ServerType    standalone
起動方法の設定。デーモンによる起動の指定(inetdから起動させたい場合はinetd)
■ServerAdmin
管理者のメールアドレス
■Port       21
使用するポート番号(この場合標準のポートを指定)
■Umask        022
デフォールトのumaskとして022を使用し、新しく作られたファイルやディレクトリの安全性を高める
■SyslogFacility    LOCAL6
Syslogの設定(SyslogファシリティとしてLOCAL6を使用する)
■TransferLog     /var/log/xferlog
ファイル転送ログを指定する (デフォールトは/var/log/message)
不要な場合は'NONE'を指定する
■MaxInstances    30
DoS攻撃を避けるために、子プロセスの数を30に制限する(STANDALONEモードのみで有効)
■User    nobody
■Group    nobody
ユーザーが認証されていないときに、ftpデーモンを実行するユーザーとグループ

■DefaultRoot  ~   !wheel
デフォルトパスの指定
※接続されたユーザーについてユーザーディレクトリをルートとするように設定 また、ユーザーがwheelグループに属しているときは全てのディレクトリを表示可能に設定と言う意味。
全てのユーザーに適用する場合は(DefaultRoot     ~)


anonymous接続する場合

まず、anonymous専用のユーザーを作成する必要があります。adduserで作成するか、vipwでユーザーとディレクトリーを個々に作成してやります。
adduserで作成するよりも、vipwで作成した方が安全のような気がするので、vipwで作成してみました。
コマンドラインからvipwで以下のようなユーザーの作成
ftp:*:1004:1004::0:0:anonymous ftp:/usr/home/ftp:/bin/sh

/etc/groupに以下のようなグループの追加
ftp:*:1004:

使用するディレクトリーの作成と所有権の設定等

hoge# mkdir /usr/home/ftp
hoge# chown ftp:ftp /usr/home/ftp
hoge# chmod 755 /usr/home/ftp

準備が整ったのでconfigファイルを設定します。
configファイルの設定は、以下の様な感じになります。
# 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			"ホストサーバードメイン"
ServerType			standalone
ServerAdmin			"管理者のメールアドレス"
DefaultServer			on

# Port 21 is the standard FTP port.
Port				21
# 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

# Set the user and group that the server normally runs at.
User				nobody
Group				nogroup

# Normally, we want files to be overwriteable.
<Directory /*>
  AllowOverwrite		on
</Directory>

# A basic anonymous configuration, no upload directories.
<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>
DefaultRoot	~	!wheel



■RequireValidShell     off
/etc/shellにシェルバイナリが登録されていなくても接続可能
■UserAlias      anonymous ftp
ログイン名としてanonymousを定義する
■MaxClients         10
Anonymousログインの同時接続数を制限
■DisplayLogin          welcome.msg
ログインしたときに表示されるファイルの名前
■DisplayFirstChdir        .message
ディレクトリを変更したときに表示されるファイルの名前
      <Limit WRITE>
      DenyAll
      </Limit>
ディレクトリの作成、削除、ファイルの作成、更新、削除は許可しない


各ディレクトリーへ制限をかける場合
#<Anonymous ~ftp> </Anonymous ~ftp>の中に記述した場合(各ディレクトリーは予め作成しておく)

  # 書き込み専用ディレクトリ ~ftp/incomingの設定
  <Directory incoming/*>
    AllowOverwrite	on	# 上書きを許可
    <Limit READ DIRS>	# ファイルの読出と、ディレクトリの一覧を
      DenyAll		# どこからでも禁止する
    </Limit>
    <Limit WRITE>              # 書き込みを
      AllowAll                 # どこからでも許可する
    </Limit>
  </Directory>

  # ファイル一覧ができない読み出し専用ディレクトリ ~ftp/outgoingの設定
  <Directory outgoing/*>
    <Limit READ>               # 読み出しを
      AllowAll                 # どこからでも許可する
    </Limit>
    <Limit WRITE DIRS>         # ファイルの書込と、ディレクトリの一覧を
      DenyAll                  # どこからでも禁止する
    </Limit>
  </Directory>
  
  # pubディレクトリに対しては、いっさいFTPコマンドを受け付けない
  <Directory pub>
    <Limit ALL>
      DenyAll
    </Limit>
  </Directory6gt


ログインの制限する場合
<Limit LOGIN>
  Order Allow, Deny
  AllowUser ftp
  Allow from 192.168.xxx.
  Deny from All
</Limit>

  • ユーザftp(anonymous)はどこからでもアクセス可能
  • それ以外のユーザは、 192.168.xxx.0/24のネットワークからのみアクセス可能


システムの設定

/etc/inetd.confの中身を開いて以下の行をコメントアウトします。
#ftp   stream   tcp   nowait  root  /usr/libexec/ftpd  ftpd  -l

そして、/usr/local/etc/rc.d/の中に以下の自動起動スクリプトを置いて、実行権を与えておきます。
#!/bin/sh
echo -n ' proftpd'
/usr/local/proftpd/sbin/proftpd start > /dev/null

ProFTPの起動

ftpの設定を解除するためにinetdを再起動します。
# kill -1 `cat /var/run/inetd.pid`;/usr/local/proftpd/sbin/proftpd
最後にProFTPDデーモンを起動します。
# /usr/local/proftpd/sbin/proftpd start

以上で設定は完了です。
BACK