{"id":172,"date":"2011-10-21T12:16:23","date_gmt":"2011-10-21T04:16:23","guid":{"rendered":"http:\/\/www.321211.net\/wordpress\/?p=172"},"modified":"2011-10-21T12:16:23","modified_gmt":"2011-10-21T04:16:23","slug":"%e8%bd%ac%e8%b4%b4vsftpdmysql%e8%99%9a%e6%8b%9f%e7%94%a8%e6%88%b7%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.321211.xyz\/?p=172","title":{"rendered":"(\u8f6c\u8d34)vsftpd+mysql\u865a\u62df\u7528\u6237\u914d\u7f6e"},"content":{"rendered":"<p>2009.07.12 Tsengyia#126.com http:\/\/selinux.cublog.cn ########################################################################## \u7cfb\u7edf\u73af\u5883\uff1aRHEL5 [ 2.6.18-8.el5xen ] \u8f6f\u4ef6\u73af\u5883\uff1a RHEL5\u5149\u76d8\u81ea\u5e26\u7684\u8f6f\u4ef6\u5305\u2014\u2014 httpd-2.2.3-6.el5 mysql-server-5.0.22-2.1 mysql-5.0.22-2.1 mysql-devel-5.0.22-2.1 mysql-connector-odbc-3.51.12-2.2 php-mysql-5.1.6-5.el5 php-5.1.6-5.el5 php-pdo.5.1.6-5.el5 php-mbstring-5.1.6-5.el5 \u9700\u53e6\u884c\u4e0b\u8f7d\u7684\u8f6f\u4ef6\u5305\u2014\u2014 pam_mysql-0.7pre2.tar.gz (http:\/\/sourceforge.net\/projects\/pam-mysql\/) phpMyAdmin-2.11.9.5-all-languages.tar.gz (http:\/\/www.phpmyadmin.net\/) ########################################################################## \u4e00\u3001\u5b89\u88c5\u8f6f\u4ef6\u5305 1. \u5b89\u88c5\u914d\u7f6ehttpd\u3001mysql\u3001mysql-devel\u3001php\u8f6f\u4ef6\u5305\uff08\u7565\uff09 2. \u5b89\u88c5\u914d\u7f6ephpMyAdmin\u8f6f\u4ef6\u5305\uff0c\u4ee5\u65b9\u4fbf\u901a\u8fc7Web\u754c\u9762\u7ba1\u7406MySQL\u6570\u636e\u5e93\u7cfb\u7edf\uff08\u7565\uff09 3. \u5b89\u88c5vsftpd\u8f6f\u4ef6\u5305\uff08\u7565\uff09 \u2014\u2014 \u82e5\u4e0d\u9700\u8981\u901a\u8fc7Web\u754c\u9762\u7ba1\u7406\u6570\u636e\u5e93\uff08\u4e2d\u7684\u865a\u62df\u7528\u6237\uff09\uff0c\u53ef\u4ee5\u4e0d\u5b89\u88c5httpd\u3001php\u3001phpMyAdmin \u4e8c\u3001\u521b\u5efa\u6620\u5c04\u7528\u6237\u53ca\u865a\u62df\u7528\u6237\u8d26\u53f7 1. \u521b\u5efa\u6620\u5c04\u7528\u6237virtual shell&gt; useradd -d \/ftproot -s \/sbin\/nologin virtual \/\/\u65e0\u9700\u4e3a\u8be5\u7cfb\u7edf\u8d26\u53f7\u8bbe\u7f6e\u5bc6\u7801 shell&gt; chmod 755 \/ftproot \/\/\u6b64\u76ee\u5f55\u4f5c\u4e3a\u6240\u6709\u865a\u62df\u7528\u6237\u8d26\u53f7\u7684\u9ed8\u8ba4FTP\u6839\u76ee\u5f55 2. \u521b\u5efa\u865a\u62df\u7528\u6237\u8d26\u53f7tsengyia\u3001kylin shell&gt; service mysqld start shell&gt; mysql -u root -p mysql&gt; create database vusersdb; mysql&gt; use vusersdb; mysql&gt; create table vusers(name char(16),passwd char(48),primary key (name)); mysql&gt; insert into vusers values(&#8216;tsengyia&#8217;,password(&#8216;123pw&#8217;)); \/\/\u6dfb\u52a0\u865a\u62df\u7528\u6237\u8d26\u53f7tsengyia mysql&gt; insert into vusers values(&#8216;kylin&#8217;,password(&#8216;456pw&#8217;)); \/\/\u6dfb\u52a0\u865a\u62df\u7528\u6237\u8d26\u53f7kylin mysql&gt; grant select on vusersdb.vusers to virtual@localhost identified by &#8216;pw@topscrt&#8217;; \/\/\u4e3a\u6620\u5c04\u7528\u6237\u8d4b \u4e88\u67e5\u8be2\u6743\u9650 \u2014\u2014 \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4eceMySQL4.1\u7248\u672c\u5f00\u59cb\uff0cpassword()\u51fd\u6570\u751f\u6210\u7684\u52a0\u5bc6\u5b57\u4e32\u9700\u8981\u5360\u752841\u4e2a\u5b57\u8282\uff0c\u56e0\u6b64vusers\u8868\u4e2d\u7684passwd\u5b57\u6bb5\u5bbd\u5ea6\u5e94\u5927\u4e8e\u6216\u7b49\u4e8e\u8be5\u503c\uff0c\u5426\u5219\u5c06\u5bfc\u81f4\u865a\u62df\u7528\u6237\u9a8c\u8bc1\u5931\u8d25 \u540e\u7eed\u5bf9\u865a\u62df\u7528\u6237\u8d26\u53f7\u7684\u7ba1\u7406\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u9014\u5f84\uff1a 1) \u76f4\u63a5\u4f7f\u7528mysql\u8bed\u53e5\u5728vusers\u8868\u4e2d\u6dfb\u52a0\u3001\u5220\u9664\u3001\u4fee\u6539\u8d26\u53f7\u8bb0\u5f55 2) \u4f7f\u7528phpMyAdmin\u5957\u4ef6\u7684Web\u7ba1\u7406\u754c\u9762\u7ba1\u7406\u8d26\u53f7\u8bb0\u5f55 \u4e09\u3001\u5efa\u7acb\u652f\u6301\u6570\u636e\u5e93\u7684PAM\u8ba4\u8bc1\u6587\u4ef6 1. \u5b89\u88c5pam-mysql\u8f6f\u4ef6\u5305 shell&gt; tar zxvf pam_mysql-0.7pre2.tar.gz shell&gt; .\/configure shell&gt; make install shell&gt; ln -sf \/usr\/lib\/security\/pam_mysql.so \/lib\/security \/\/\u5efa\u7acb\u7b26\u53f7\u8fde\u63a5\u4ee5\u65b9\u4fbf\u7cfb\u7edf\u81ea\u52a8\u627e\u5230\u6a21\u5757 2. \u5efa\u7acbPAM\u8ba4\u8bc1\u6587\u4ef6 shell&gt; cp \/etc\/pam.d\/vsftpd \/etc\/pam.d\/vsftpd.vu shell&gt; vi \/etc\/pam.d\/vsftpd.vu #%PAM-1.0 #\/\/\u4ee5\u4e0b2\u884c\u5185\u5bb9\u7528\u4e8e\u865a\u62df\u7528\u6237\u8ba4\u8bc1\uff0c\u82e5\u53ea\u9700\u4f7f\u7528\u865a\u62df\u7528\u6237\u8d26\u53f7\uff0c\u53ef\u4ee5\u5c06\u5176\u4e2d\u7684\u201csufficient\u201d\u6539\u4e3a\u201crequired\u201d\uff0c\u5e76\u5220\u9664\u5176\u4ed6\u914d\u7f6e\u53c2\u6570 auth sufficient pam_mysql.so user=virtual passwd=pw@topscrt host=localhost db=vusersdb table=vusers usercolumn=name passwdcolumn=passwd crypt=2 account sufficient pam_mysql.so user=virtual passwd=pw@topscrt host=localhost db=vusersdb table=vusers usercolumn=name passwdcolumn=passwd crypt=2 #\/\/\u6b64\u884c\u4ee5\u4e0b\u4e3a\u539f\u6709PAM\u8ba4\u8bc1\u6587\u4ef6\u4e2d\u7684\u914d\u7f6e\u5185\u5bb9\uff0c\u53ef\u4ee5\u4fdd\u7559\u4ee5\u4fbf\u540c\u65f6\u652f\u6301\u7cfb\u7edf\u7528\u6237\u8d26\u53f7 session optional pam_keyinit.so force revoke auth required pam_listfile.so auth required pam_shells.so auth include system-auth account include system-auth session include system-auth session required pam_loginuid.so \u2014\u2014\u5728\u4e0a\u8ff0pam_mysql.so\u7684\u8ba4\u8bc1\u53c2\u6570\u4e2d\uff0ccrypt\u7684\u53d6\u503c\u8868\u793a\u4f7f\u7528\u4e0d\u540c\u7684\u5bc6\u7801\u52a0\u5bc6\u65b9\u5f0f\uff0c\u53d6\u503c\u5982\u4e0b\uff1a 0\u6216\u8005\u201cplain\u201d\uff0c\u4f7f\u7528\u660e\u6587\u5bc6\u7801\uff1b 1\u6216\u8005\u201cY\u201d\uff0c\u4f7f\u7528crypt()\u51fd\u6570\u52a0\u5bc6\uff1b 2\u6216\u8005\u201cmysql\u201d\uff0c\u4f7f\u7528MySQL\u7684password()\u51fd\u6570\u52a0\u5bc6\uff1b 3\u6216\u8005\u201cmd5\u201d\uff0c\u4f7f\u7528MD5\u52a0\u5bc6\uff1b 4\u6216\u8005\u201csha1\u201d\uff0c\u4f7f\u7528SHA1\u52a0\u5bc6\u3002 \u2014\u2014 \u5173\u4e8epam_mysql\u7684\u5404\u9879PAM\u914d\u7f6e\u53c2\u6570\u53ef\u4ee5\u53c2\u8003\u6e90\u7801\u76ee\u5f55\u4e2d\u7684README\u6587\u6863 \u56db\u3001\u8c03\u6574vsftpd\u670d\u52a1\u914d\u7f6e 1. \u4fee\u6539vsftpd.conf\u4e3b\u914d\u7f6e\u6587\u4ef6 shell&gt; vi \/etc\/vsftpd\/vsftpd.conf anonymous_enable=YES \/\/\u542f\u7528\u533f\u540dFTP\u7528\u6237 anon_umask=022 local_enable=YES &amp;nbs p; \/\/\u542f\u7528\u672c\u5730\u7cfb\u7edf\u7528\u6237 local_umask=022 chroot_local_user=YES write_enable=YES dirmessage_enable=YES xferlog_enable=YES xferlog_std_format=YES connect_from_port_20=YES pasv_min_port=12500 pasv_max_port=12800 userlist_enable=NO tcp_wrappers=YES guest_enable=YES \/\/\u542f\u7528\u865a\u62df\u7528\u6237\u652f\u6301 guest_username=virtual pam_service_name=vsftpd.vu \/\/\u4f7f\u7528\u7684PAM\u8ba4\u8bc1\u6587\u4ef6 user_config_dir=\/etc\/vsftpd\/vudir \/\/\u8bbe\u7f6e\u4e2a\u522b\u865a\u62df\u7528\u6237\u7684\u8d26\u53f7\u914d\u7f6e\u6587\u4ef6\u6240\u5728\u6587\u4ef6\u5939 \u2026\u2026 \u2014\u2014 \u5173\u4e8evsftpd.conf\u6587\u4ef6\u4e2d\u7684\u5404\u914d\u7f6e\u53c2\u6570\uff0c\u53ef\u4ee5\u53c2\u8003\u5176man\u624b\u518c\u9875 2. \u4e3a\u4e2a\u522b\u865a\u62df\u7528\u6237\u5efa\u7acb\u5355\u72ec\u7684\u914d\u7f6e\u6587\u4ef6 shell&gt; mkdir \/etc\/vsftpd\/vudir shell&gt; vi \/etc\/vsftpd\/vudir\/tsengyia anon_upload_enable=YES \/\/\u5141\u8bb8\u4e0a\u4f20 anon_mkdir_write_enable=YES \/\/\u5141\u8bb8\u521b\u5efa\u76ee\u5f55 anon_other_write_enable=YES \/\/\u5141\u8bb8\u5220\u9664\u3001\u6539\u540d\u6587\u4ef6\u6216\u76ee\u5f55\u7b49 shell&gt; vi \/etc\/vsftpd\/vudir\/kylin download_enable=NO \/\/\u7981\u6b62\u4e0b\u8f7d shell&gt; useradd jerry shell&gt; passwd jerry shell&gt; chown -R virtual.virtual \/home\/jerry shell&gt; vi \/etc\/vsftpd\/vudir\/jerry local_root=\/home\/jerry \/\/\u767b\u9646\u540e\u7684FTP\u6839\u76ee\u5f55\u6539\u4e3a\/home\/jerry\uff0c\u82e5\u65e0\u6b64\u9879\u914d\u7f6e\u5219\u4ecd\u7136\u5bf9\u5e94\u4e3a\/ftproot anon_upload_enable=YES \u4e94\u3001\u542f\u52a8vsftpd\u670d\u52a1\uff0c\u5e76\u8fdb\u884c\u6d4b\u8bd5 1. \u4ee5\u533f\u540d\u7684\u65b9\u5f0f\u767b\u9646FTP\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u6d4f\u89c8\u76ee\u5f55\u3001\u4e0b\u8f7d\u6587\u4ef6\uff0c\u4f46\u4e0d\u5177\u6709\u4e0a\u4f20\u6743\u9650 2. \u4ee5\u865a\u62df\u7528\u6237\u8d26\u53f7tsengyia\u767b\u9646FTP\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u6d4f\u89c8\u76ee\u5f55\u3001\u4e0b\u8f7d\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u4e0a\u4f20\u6587\u4ef6\u3001\u5efa\u7acb\u76ee\u5f55\u3001\u5220\u9664\u53ca\u6539\u540d\u6587\u4ef6\u548c\u76ee\u5f55\u7b49 3. \u4ee5\u865a\u62df\u7528\u6237\u8d26\u53f7kylin\u767b\u9646FTP\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u6d4f\u89c8\u76ee\u5f55\u5185\u5bb9\uff0c\u4f46\u7981\u6b62\u4e0b\u8f7d\u6587\u4ef6 4. \u4ee5\u7cfb\u7edf\u7528\u6237\u8d26\u53f7jerry\u767b\u9646FTP\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u6d4f\u89c8\u76ee\u5f55\u3001\u4e0b\u8f7d\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u4e0a\u4f20\u6587\u4ef6\uff0c\u4f46\u4e0d\u5177\u5907\u5176\u4ed6\u5199\u5165\u6743\u9650<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2009.07.12 Tsengyia#126.com http:\/\/selinux.cublog.cn ## [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-172","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.321211.xyz\/index.php?rest_route=\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.321211.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.321211.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.321211.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.321211.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172"}],"version-history":[{"count":2,"href":"https:\/\/www.321211.xyz\/index.php?rest_route=\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":174,"href":"https:\/\/www.321211.xyz\/index.php?rest_route=\/wp\/v2\/posts\/172\/revisions\/174"}],"wp:attachment":[{"href":"https:\/\/www.321211.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.321211.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.321211.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}