「vsFTPd」の「chroot」環境の設定をします。
(1)「vsFTPd」の設定変更を行う。
[root@example ~]# vi /etc/vsftpd/vsftpd.conf #--最終行にでも追加-- # Chroot Setting. chroot_local_user=YES # ローカルユーザは全て自分のホームディレクトリへchrootする。 chroot_list_enable=YES # chrootの設定を外すユーザを指定できるようにする。 chroot_list_file=/etc/vsftpd/chroot/chroot_list # chrootの設定を外すユーザを記入するファイルを指定する。
(2)「chroot」ディレクトリ(chroot_listを保存する)とchroot_listの作成をする。
[root@example ~]# mkdir /etc/vsftpd/chroot [root@example ~]# vi /etc/vsftpd/chroot/chroot_list test_user2
※この設定では、「test_user2」のみがchroot環境から外れます。
(3)「vsFTPd」の再起動をする。
[root@example ~]# /etc/rc.d/init.d/vsftpd restart vsftpd を停止中: [ OK ] vsftpd 用の vsftpd を起動中: [ OK ]
(4)動作確認をする。
ここでは、「test_user1」と「test_user2」を作成しFTPでログインしてchroot設定に問題ないか確認してみる。
1. ユーザーの作成
[root@example ~]# useradd test_user1 [root@example ~]# useradd test_user2 [root@example ~]# passwd test_user1 [root@example ~]# passwd test_user2
2. test_user1でFTPログインする
[root@example ~]# ftp localhost Connected to test.local. 220 Welcome to blah FTP service. 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (localhost:root): test_user1 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> pwd 257 "/" ftp> cd .. 250 Directory successfully changed. ftp> pwd 257 "/"
※test_user1は問題なくchrootされていることを確認。
3. test_user2でFTPログインする
[root@example ~]# ftp localhost Connected to test.local. 220 Welcome to blah FTP service. 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (localhost:root): test_user2 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> pwd 257 "/home/test_user2" ftp> cd .. 250 Directory successfully changed. ftp> ls 227 Entering Passive Mode (127,0,0,1,180,90) 150 Here comes the directory listing. drwx------ 2 500 500 4096 May 03 06:08 test drwx------ 2 501 501 4096 May 03 07:02 test_user1 drwx------ 2 502 502 4096 May 03 07:02 test_user2 226 Directory send OK. ftp> pwd 257 "/home"
※test_user2はhomeディレクトリより上層のディレクトリへ移動(参照)できるのでchrootからは外れていることを確認。
〇「chroot」の環境でユーザー毎にログイン先を変更する方法
ここでは、ユーザー毎にログイン先ディレクトリを変更してみます。
・ログイン先
test_user1 -> /var/www/test_user1
test_user2 -> /opt/test_user2
※ログイン先ディレクトリは作成されているものとします。
※また、test_user2は既に「chroot_list」に記述されているものとします。
(5)「vsFTPd」の設定を変更します。
[root@example ~]# vi /etc/vsftpd/vsftpd.conf # Chroot Setting. chroot_local_user=YES chroot_list_enable=YES chroot_list_file=/etc/vsftpd/chroot/chroot_list user_config_dir=/etc/vsftpd/vsftpd_user_conf # 追加
(6)ログイン先変更ファイルを保存するディレクトリを作成する。
[root@example ~]# mkdir /etc/vsftpd/vsftpd_user_conf
(7)各ユーザーの設定ファイルを作成する。
[root@example ~]# vi /etc/vsftpd/vsftpd_user_conf/test_user1 local_root=/var/www/test_user1 [root@example ~]# vi /etc/vsftpd/vsftpd_user_conf/test_user2 local_root=/opt/test_user2
※必ずファイル名はユーザ名で作成しましょう
(8)「vsFTPd」の再起動をする。
[root@example ~]# /etc/rc.d/init.d/vsftpd restart vsftpd を停止中: [ OK ] vsftpd 用の vsftpd を起動中: [ OK ]
(9)動作を確認する。
1. test_user1でFTPログインした場合
[root@example ~]# ftp localhost Connected to test.local. 220 Welcome to blah FTP service. 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (localhost:root): test_user1 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> pwd 257 "/" ftp> mkdir test_directory 257 "/test_directory" created ftp> quit 221 Goodbye. [root@example ~]# ls -l /var/www/test_user1/ 合計 4 drwxr-xr-x 2 test_user1 test_user1 4096 5月 3 16:32 test_directory
2. test_user2でFTPログインした場合
[root@example ~]# ftp localhost Connected to test.local. 220 Welcome to blah FTP service. 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (localhost:root): test_user2 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> pwd 257 "/" ftp> mkdir test_directory 257 "/test_directory" created ftp> quit 221 Goodbye. [root@example ~]# ls -l /opt/test_user2/ 合計 4 drwxr-xr-x 2 test_user2 test_user2 4096 5月 3 16:35 test_directory