
Ubuntu 12.10에서 vsftpd 및 MySQL을 사용한 가상 호스팅
MySQL 데이터베이스 관리를 위해 이 하우투에서도 설치될 phpMyAdmin과 같은 웹 기반 도구를 사용할 수 있습니다. phpMyAdmin은 편리한 그래픽 인터페이스이므로 명령줄을 어지럽힐 필요가 없습니다.
이 튜토리얼은 Ubuntu 12.10을 기반으로 합니다. 기본 Ubuntu 12.10 시스템이 이미 설정되어 있어야 합니다.
This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.
This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!
1 서문
In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.
Because we must run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing
sudo su
2 vsftpd, MySQL 및 phpMyAdmin 설치
Vsftpd has no built-in MySQL support, therefore we must use PAM to authenticate against the MySQL database. So we install libpam-mysql in addition to vsftpd, MySQL, and phpMyAdmin:
apt-get install vsftpd libpam-mysql mysql-server mysql-client phpmyadmin libpam-ldap
You will be asked the following questions:
New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword
Web server to reconfigure automatically: <-- apache2
Configure database for phpmyadmin with dbconfig-common? <-- No
LDAP server Uniform Resource Identifier: <-- ENTER
Distinguished name of the search base: <-- ENTER
LDAP version to use: <-- 3
Make local root Database admin: <-- Yes
Does the LDAP database require login? <-- No
LDAP account for root: <-- ENTER
LDAP root account password: <-- ldaprootpw
3 vsftpd용 MySQL 데이터베이스 생성
Now we create a database called vsftpd and a MySQL user named vsftpd which the vsftpd daemon will use later on to connect to the vsftpd database:
mysql -u root -p
CREATE DATABASE vsftpd;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO 'vsftpd'@'localhost' IDENTIFIED BY 'ftpdpass';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON vsftpd.* TO 'vsftpd'@'localhost.localdomain' IDENTIFIED BY 'ftpdpass';
FLUSH PRIVILEGES;
Replace the string ftpdpass with whatever password you want to use for the MySQL user vsftpd. Still on the MySQL shell, we create the database table we need (yes, there is only one table!):
USE vsftpd;
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;
As you may have noticed, with the quit; command we have left the MySQL shell and are back on the Linux shell.
BTW, (I'm assuming that the hostname of your ftp server system is server1.example.com) you can access phpMyAdmin under http://server1.example.com/phpmyadmin/ (you can also use the IP address instead of server1.example.com) in a browser and log in as the user vsftpd. Then you can have a look at the database. Later on you can use phpMyAdmin to administrate your vsftpd server.
4 vsftpd 구성
First we create a non-privileged user called vsftpd (with the homedir /home/vsftpd) belonging to the group nogroup. We will run vsftpd under this user, and the FTP directories of our virtual users will be in the /home/vsftpd directory (e.g. /home/vsftpd/user1, /home/vsftpd/user2, etc.).
useradd --home /home/vsftpd --gid nogroup -m --shell /bin/false vsftpd
Then we make a backup of the original /etc/vsftpd.conf file and create our own:
cp /etc/vsftpd.conf /etc/vsftpd.conf_orig
cat /dev/null > /etc/vsftpd.conf
vi /etc/vsftpd.conf
The file should have the following contents:
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 rsa_cert_file=/etc/ssl/certs/vsftpd.pem 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 |
user_config_dir 옵션을 사용하면 전역 설정의 일부를 재정의하는 사용자별 구성 파일의 디렉터리를 지정할 수 있습니다. 이것은 완전히 선택 사항이며 이 기능을 사용하려는 경우 사용자에게 달려 있습니다. 그러나 지금 해당 디렉토리를 생성해야 합니다.
mkdir /etc/vsftpd_user_conf이제/etc/passwd 및/etc/shadow 대신 MySQL 데이터베이스를 사용하여 가상 FTP 사용자를 인증하도록 PAM을 구성해야 합니다. vsftpd의 PAM 구성은/etc/pam.d/vsftpd에 있습니다. 원본 파일을 백업하고 다음과 같이 새 파일을 만듭니다.
cp/etc/pam.d/vsftpd/etc/pam.d/vsftpd_orig
고양이/dev/null >/etc/pam.d/vsftpd
vi/etc/pam.d/vsftpd
auth required pam_mysql.so user=vsftpd passwd=ftpdpass host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=2 account required pam_mysql.so user=vsftpd passwd=ftpdpass host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=pass crypt=2
MySQL 비밀번호를 자신의 비밀번호로 교체했는지 확인하십시오!
그런 다음 vsftpd를 다시 시작합니다.
/etc/init.d/vsftpd restart
5 첫 번째 가상 사용자 생성
데이터베이스를 채우려면 MySQL 셸을 사용할 수 있습니다.
mysql -u root -p
USE vsftpd;이제 암호 비밀(MySQL의 PASSWORD 기능을 사용하여 암호화되어 저장됨)을 사용하여 가상 사용자 testuser를 생성합니다.
INSERT INTO 계정(사용자 이름, 통과) VALUES('testuser', PASSWORD('secret'));
그만두다;
testuser의 홈 디렉토리는/home/vsftpd/testuser입니다. 불행히도 vsftpd는 존재하지 않는 경우 해당 디렉토리를 자동으로 생성하지 않습니다. 따라서 지금 수동으로 생성하고 vsftpd 사용자와 nogroup 그룹이 소유하도록 합니다.
mkdir/home/vsftpd/testuser
chown vsftpd:nogroup/home/vsftpd/testuser
이제 워크 스테이션에서 FTP 클라이언트 프로그램(FileZilla 또는 FireFTP 등)을 열고 연결을 시도합니다. 호스트 이름으로 server1.example.com(또는 시스템의 IP 주소)을 사용하고 사용자 이름은 testuser이고 암호는 secret입니다.
연결할 수 있다면 축하합니다! 그렇지 않은 경우 문제가 발생했습니다.
6 데이터베이스 관리
대부분의 사람들에게 MySQL에 대한 그래픽 프론트엔드가 있으면 더 쉽습니다. 따라서 phpMyAdmin(이 예에서는 http://server1.example.com/phpmyadmin/에 있음)을 사용하여 vsftpd 데이터베이스를 관리할 수도 있습니다.

사용자를 생성하거나 수정할 때마다 MySQL의 PASSWORD 기능을 사용하여 해당 사용자의 비밀번호를 암호화해야 합니다. 또한 새로운 가상 사용자를 생성할 때 이전 장의 끝 부분에 표시된 것처럼 쉘에 해당 사용자의 homedir을 생성하는 것을 잊지 마십시오.
