歡迎您光臨本站 註冊首頁

vsftp伺服器配置(二)

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

四、 使用pam實現虛擬用戶(適用於standalone啟動與xinetd啟動)

1. 配置 實現vsftp虛擬用戶的關鍵是創建vsftp的pam用戶數據文件和修改vsftpd的pam配置文件.具體實驗步驟如下: 1) 建立包含虛擬用戶名稱和密碼的文本文件,文件奇數行為用戶名,偶數行為用戶密碼.例如: [root@RHEL5 mnt]# vi login.txt test 123456 oralce 123456 2) 將包含虛擬用戶的文本轉換成資料庫文件. db_load -T -t hash -f login.txt /etc/vsftpd/vsftpd_login.db db_load命令包含在db4-utils軟體包中,如果系統中不存在該命令安裝此包可以解決. 3) 修改vsftp的pam配置文件/etc/pam.d/vsftpd.將文件內容修改為以下(可以重新新建一個文件.把以前的進行備份.): [root@RHEL5 pam.d]# vi vsftpd auth required pam_userdb.so db=/etc/vsftpd/vsftpd_login account required pam_userdb.so db=/etc/vsftpd/vsftpd_login 4) 檢查vsftpd.conf文件必須包含以下選項: guest_enable=yes guest_username=ftp pam_service_name=vsftpd 5) 重起vsftp服務 service vsftpd restart 2. 測試 [root@RHEL5 ~]# ftp 192.168.88.22 Connected to 192.168.88.22. 220 (vsFTPd 2.0.1) 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (192.168.88.22:root): test 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 227 Entering Passive Mode (192,168,88,22,250,147) 150 Here comes the directory listing. -rw-r--r-- 1 0 0 8 Jan 02 10:16 mm

drwx---rwx 2 0 0 4096 Jan 02 11:11 pub 226 Directory send OK. ftp> 還可以為不同的虛擬用戶創建獨立的配置文件,該參數指明用戶的獨立配置文件的存放位置,在配置文件中添加此參數. User_config_dir=/etc/vsftpd/userconf 創建User_config_dir=/etc/vsftpd/userconf目錄並在該目錄下建立與用戶同名的文件,並在文件中寫入相應的選項.例如:在文件test中寫如”write_enable=no”.重新啟動vsftp伺服器使修改生效. [root@RHEL5 ~]# cd /etc/vsftpd [root@RHEL5 vsftpd]# mkdir userconf [root@RHEL5 vsftpd]# cd userconf/ [root@RHEL5 userconf]# vi test write_enable=no 測試如下: [root@RHEL5 ~]# ftp 192.168.88.22 Connected to 192.168.88.22. 220 (vsFTPd 2.0.1) 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (192.168.88.22:root): test 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 227 Entering Passive Mode (192,168,88,22,251,229) 150 Here comes the directory listing. -rw-r--r-- 1 0 0 8 Jan 02 10:16 mm drwx---rwx 2 0 0 4096 Jan 02 11:19 pub 226 Directory send OK. ftp> cd pub 250 Directory successfully changed. ftp> ls 227 Entering Passive Mode (192,168,88,22,112,205) 150 Here comes the directory listing. 226 Directory send OK. ftp> mkdir mm 550 Permission denied. ftp> bye 221 Goodbye. [root@node1 ~]# ftp 192.168.88.22 Connected to 192.168.88.22. 220 (vsFTPd 2.0.1) 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (192.168.88.22:root): oralce 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 227 Entering Passive Mode (192,168,88,22,197,148) 150 Here comes the directory listing. -rw-r--r--

1 0 0 8 Jan 02 10:16 mm drwx---rwx 2 0 0 4096 Jan 02 11:19 pub 226 Directory send OK. ftp> cd pub 250 Directory successfully changed. ftp> mkdir mm 257 "/pub/mm" created ftp> ls 227 Entering Passive Mode (192,168,88,22,210,125) 150 Here comes the directory listing. drwxr-xr-x 2 14 50 4096 Jan 02 11:20 mm 226 Directory send OK. ftp> 可以看出test用戶不能創建文件,而oralce用戶可以進行創建. 注意:對於匿名用戶,如果需要禁止匿名用戶連接ftp伺服器,那麼在配置文件中將匿名用戶的參數修改為no,不能註銷,系統本身默認為yes.即使是註銷也不會生效. 五、虛擬用戶伺服器配置(通過資料庫) 1.安裝環境 系統:RHEL5.2 資料庫:MySQL-server-community-5.1.30-0 ftp伺服器:vsftpd-2.0.5-12.el5 2.vsftp的安裝 [root@rhel5 mnt]# rpm -ivh vsftpd-2.0.5-12.el5.i386.rpm 3.創建guest用戶 vsftp伺服器採用pam模塊來實現虛擬用戶驗證.由於虛擬用戶的用戶名和口令被單獨保存,因此vsftpd在驗證的時候需要一個系統帳戶讀取資料庫文件完成驗證功能.這就是vsftpd的guest用戶,就匿名用戶一樣需要一個系統帳戶ftp. [root@rhel5 mnt]#useradd –M –d /data –s /sbin/nologin vftp [root@rhel5 mnt]#passwd vftp [root@rhel5 mnt]#chmod 700 /data [root@rhel5 mnt]#chown vftp:vftp /data 4. 安裝資料庫並將虛擬用戶保存在mysql資料庫中 安裝mysql資料庫 MySQL-client-community-5.1.30-0.rhel5.i386.rpm MySQL-server-community-5.1.30-0.rhel5.i386.rpm MySQL-shared-compat-5.1.30-0.rhel5.i386.rpm 注意: 這幾個包也必須安裝.如果沒有安裝以下包時,虛擬用戶登陸時會出問題. perl-DBI-1.52-1.fc6.i386.rpm perl-DBD-MySQL-3.0007-1.fc6.i386.rpm perl-DBD-Pg-1.49-1.fc6.i386.rpm 創建資料庫及用戶 [root@rhel5 ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 31 Server version: 5.1.30-community MySQL Community Server (GPL) Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> create database vsftpd; Query OK, 1 row affected (0.00 sec) mysql> use vsftpd; Database changed mysql> create table accounts(username varchar(20),passwd varchar(10)); Query OK, 0 rows affected (0.01 sec) mysql> insert into accounts(username,passwd) value('admin','123456'); Query OK, 1 row affected (0.00 sec) mysql> insert into accounts(username,passwd) value('upload','123456'); Query OK, 1 row affected (0.00 sec) mysql> insert into accounts(username,passwd) value('download','123456'); Query OK, 1 row affected (0.00 sec) mysql> grant select on vsftpd.accounts to vftp@localhost identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@rhel5 ~]# mysql -u vftp -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 32 Server version: 5.1.30-community MySQL Community Server (GPL) Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> use vsftpd Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from accounts; ---------- -------- | username | passwd | ---------- -------- | admin

| 123456 | | upload | 123456 | | download | 123456 | ---------- -------- 3 rows in set (0.00 sec) mysql> 5. 設置mysql的pam模塊驗證 這裡我們要用到一個利用mysql的進行pam驗證的開源項目.在http://sourceforge.net/projects/sysauth-pgsql網站可以下載所需要的包進行編譯.下載pam_mysql-0.7RC1.tar.gz進行編譯安裝.在編譯之前確保安裝了msyql的庫文件包. vsftp的pam內容如下: [root@rhel5 pam.d]# cat vsftpd #%PAM-1.0 auth required /lib/security/pam_mysql.so user=vftp passwd=123456 host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=passwd crypt=0 account required /lib/security/pam_mysql.so user=vftp passwd=123456 host=localhost db=vsftpd table=accounts usercolumn=username passwdcolumn=passwd crypt=0 [root@rhel5 pam.d]# 上面涉及到的參數,只要對應前面資料庫的設置就可以明白.這裡需要說明的參數是crypt參數.Crypt表示口令欄位中的口令的加密方式:crypt=0,口令以明文方式保存在資料庫中;crypt=1,口令使用unix系統的DES加密方式加密后保存在資料庫中;crypt=2,口令經過mysql的password()函數加密后保存. 注意: crypt=0 明文密碼 crypt=1:使用crypt()函數(對應資料庫里的encrypt(),encrypt()隨機產生salt) crypt=2:使用mysql中的password()函數加密. Crypt=3:表示使用md5的散列方式. 6.虛擬用戶進一步設置. vsftpd里新添加了virtual_use_local_privs參數,當該參數為yes時,虛擬用戶使用與本地用戶相同的許可權.但該參數為no時,虛擬用戶使用與匿名用戶相同的許可權.這兩種方法相比,後者更加嚴格一些.特別是在有寫訪問的情形下.默認情況為yes.當virtual_use_local_privs為yes時,只要設置write_enable=yes,虛擬用戶就可以擁有寫許可權.當virtual_use_local_privs為no時,對虛擬用戶的設置更加嚴格些.

1)當virtual_use_local_privs為yes時 vsftpd的配置文件內容如下: anonymous_enable=no local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=YES pam_service_name=vsftpd tcp_wrappers=YES guest_enable=yes guest_username=vftp chroot_local_user=yes local_root=/data virtual_use_local_privs=yes 這樣虛擬用戶就擁有寫入的許可權了,嘗試登陸ftp伺服器,可以正常登陸ftp伺服器. 2)當virtual_use_local_privs為no時 設置三個虛擬用戶.admin具有管理許可權;upload用戶只擁有上傳許可權;download用戶只擁有下載許可權. 設置虛擬用戶各自配置文件 [root@rhel5 ~]# mkdir /etc/vsftpd/vsftpd_user_conf [root@rhel5 ~]# cd /etc/vsftpd/vsftpd_user_conf [root@rhel5 vsftpd_user_conf]# touch admin upload download [root@rhel5 vsftpd_user_conf]# vi admin write_enable=yes anon_world_readable_only=no anon_upload_enable=yes anon_mkdir_write_enable=yes anon_other_write_enable=yes local_root=/data [root@rhel5 vsftpd_user_conf]# vi upload write_enable=yes anon_world_readable_only=no anon_upload_enable=yes anon_mkdir_write_enable=yes anon_other_write_enable=no local_root=/data [root@rhel5 vsftpd_user_conf]# vi download write_enable=no anon_world_readable_only=no anon_upload_enable=no anon_mkdir_write_enable=no anon_other_write_enable=no local_root=/data vsftpd的配置文件內容入下: anonymous_enable=no local_enable=YES local_umask=022 xferlog_enable=YES connect_from_port_20=YES xferlog_file=/var/log/vsftpd.log xferlog_std_format=YES idle_session_timeout=600 data_connection_timeout=120 listen=YES pam_service_name=vsftpd tcp_wrappers=YES guest_enable=yes guest_username=vftp chroot_local_user=yes virtual_use_local_privs=no user_config_dir=/etc/vsftpd/vsftpd_user_conf 這樣不同的用戶就具有不同的許可權登陸ftp伺服器進行操作.

本文出自 「用心品位生活!」 博客,請務必保留此出處http://dreamsanqin.blog.51cto.com/845412/530724


[火星人 ] vsftp伺服器配置(二)已經有669次圍觀

http://coctec.com/docs/linux/show-post-49011.html