3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vsftpd + MySQLでユーザーをデータベースで管理するFTPを作ってみる

Last updated at Posted at 2018-05-13
apt-get install vsftpd libpam-mysql libpam-ldap

☆質問はこう返しなさい☆
LDAP server Uniform Resource Identifier: <--  エンター
Distinguished name of the search base: <-- エンター
LDAP version to use: <-- 3 と入力
Make local root Database admin: <-- Yesを選択
Does the LDAP database require login?  <-- Noを選択
LDAP account for root: <-- エンター
LDAP root account password: <-- ldaprootpw と入力
・・・・・・


mysql -u root -p

DB作成

mysql> 
create database ☆データベース名☆;

CREATE USER '☆DB管理のユーザー名☆'@'localhost' IDENTIFIED WITH mysql_native_password AS '☆DB管理のユーザのパスワード☆'; GRANT USAGE ON *.* TO '☆DB管理のユーザー名☆'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `☆データベース名☆`.* TO '☆DB管理のユーザー名☆'@'localhost';


use ☆データベース名☆;

CREATE TABLE `accounts` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `username` VARCHAR( 30 ) NOT NULL , `pass` VARCHAR( 50 ) NOT NULL , UNIQUE ( `username` ) ) ENGINE = MYISAM

quit;

Linuxユーザーの作成

nogroupにvsftpd用のユーザーを作ってやります。
/home/vsftpd 下に(例 /home/vsftpd/user1, /home/vsftpd/user2, ....)という感じでできます。

useradd --home /home/vsftpd --gid nogroup -m --shell /bin/false vsftpd

設定ファイルの作成

vi etc/vsftpd.conf
///
listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
nopriv_user=vsftpd
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd
pam_service_name=vsftpd
guest_enable=YES
guest_username=vsftpd
local_root=/home/vsftpd/$USER
user_sub_token=$USER
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd_user_conf
listen_port=8021
///

読解して、適宜変えてください。

MySQL設定

MySQLのライブラリを読み込むようにして、データベースのカラム等を設定します。

mkdir /etc/vsftpd_user_conf

cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd_orig
cat /dev/null > /etc/pam.d/vsftpd
vi /etc/pam.d/vsftpd
///
auth required pam_mysql.so user=☆DB管理のユーザー名☆ passwd=☆DB管理のユーザーパスワード☆ host=localhost db=☆データベース名☆ table=accounts usercolumn=username passwdcolumn=pass crypt=2
account required pam_mysql.so user=☆DB管理のユーザー名☆ passwd=☆DB管理のユーザーパスワード☆ host=localhost db=☆データベース名☆ table=accounts usercolumn=username passwdcolumn=pass crypt=2
///
service vsftpd restart

これで動くはず。

ユーザーの新規追加

MySQLで
USE ☆データベース名☆;

INSERT INTO accounts (username, pass) VALUES('ユーザー名', PASSWORD('パスワード'));
quit;

コンソールで
mkdir /home/vsftpd/testuser
chown vsftpd:nogroup /home/vsftpd/testuser
chmod a-w /home/vsftpd/testuser

これでFTPアクセスできます!!!

SSL対応はまた今度の話。

Reference

https://www.howtoforge.com/virtual-hosting-with-vsftpd-and-mysql-on-ubuntu-12.04
http://e-garakuta.net/techinfo/doku.php/linux/vsftpd_mysql
http://park1.wakwak.com/~ima/centos4_vsftpd0006.html

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?