歡迎您光臨本站 註冊首頁

求助,vsftp無法添加登錄

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

求助,vsftp無法添加登錄

系統是freebsd7.0,我按照http://www.cngr.cn/article/60/403/2006/2006071951631.shtml配置以後,登錄提示說用戶密碼錯誤,究竟pam要怎麼設置才行阿?另外我參考了http://www.howtoforge.com/virtual_hosting_vsftpd_postgresql_freebsd,也不行,請各位老大幫幫忙。謝謝~:em03:
《解決方案》

vsftpd的虛擬用戶配置:PAM + PgSQL + FreeBSD-4
(1.0beta,歡迎debug,本人也會隨時更新)
vsftpd可能是世界上最好的ftpd。它在linux世界非常流行,安全,性能高。
本文的目的是讓PgSQL存儲你的vsftp的虛擬用戶和密碼,通過一個叫做pam的東東來認證。

零、簡述PAM原理。
如果你已經對pam有所了解,請跳過,我知道的可能還不如你多。你不感興趣也請跳過,因為不看這個也可配置。
代碼:

用戶 <-> vsftpd <-> PAM模塊 <-> 用戶和密碼資料庫


vsftpd用了一種很聰明同時也是unix/linux規範的方法來認證用戶,就是PAM。大家對於PAM,也許有些陌生,但是一直在用。所謂PAM,英文是:Pluggable Authentication Modules,可拔插認證模塊(不知道這樣翻譯對不對)。看見plug這個關鍵字,就知道是很靈活的。
現在幾乎所有daemon程序一般都是用PAM來進行認證的,包括telnet/sshd/imapd,甚至你的login,都是用PAM。在 fbsd 4上的朋友,你可以打ps -ax|grep pam,你會發現login了多少個控制台,就會有多少個寫著pam的進程。

PAM的最大好處是靈活。它不管你的用戶和密碼用什麼數據格式存儲(資料庫也好,通常用的密碼文件也好),只要有相應的PAM模塊就可以存儲。比如說,大家不僅可以用vsftpd + PgSQL做用戶登陸驗證,只要你喜歡你還可以用MySQL,Oracle,LDAP資料庫存儲用戶數據,只要有相應的PAM就可以。所有的daemon 都可以用一個後台資料庫來做用戶驗證登陸,包括telnet/sshd等等。

pam的配置機制在不同版本的freebsd上有差異。
freebsd-4放在/etc/pam.conf,一個文件記錄所有pam服務。
freebsd-5放在/etc/pam.d,/usr/local/etc/pam.d。每個pam服務由一個獨立的文件記錄。

本文不打算詳細敘述PAM的配置。PAM的配置不是很難,畢竟,只是要你配置一些參數,不是叫你開發一個pam模塊出來。而且本文的篇幅所限,偶剛剛知道的一點東西希望能夠起到拋磚引玉的作用。等偶對pam再玩得深入和熟一點的時候,再寫一篇關於深入一點關於pam的東東?

準備開始:提要
簡單講講要用到的配置文件的作用。
引用:

/etc/pam.conf #pam服務的配置
/etc/pam_pgsql.conf #pam_pgsql.so的配置
/usr/local/etc/vsftpd.conf #vsftpd的配置



一、安裝vsftpd,PostgreSQL,pam_pgsql。
我都是使用port來安裝的,請大家用port/package來安裝,不要自己下載源碼來編譯,否則可能根據本文的方法可能無法正常使用。其中vsftpd和pam-pgsql一定要用port/package來安裝。
以下是他們的port目錄:
引用:

/usr/ports/ftp/vsftpd
/usr/ports/databases/postgresql7
/usr/ports/security/pam-pgsql



安裝:只要cd進去,然後make install就OK了。

二、PostgreSQL安裝(如果你已經有了PostgreSQL,不需要看這一節)
簡單提提用port來裝PostgreSQL的過程,因為BSD版上的裝PgSQL的方法都是自己下載源碼編譯的。我是用port來編譯安裝,因為這是fbsd推薦的安裝方法,而且安裝的軟體會根據bsd的hier(目錄結構)來安裝,比較便於管理。
當用port來安裝好PostgreSQL,默認的資料庫管理用戶是pgsql(port裡頭的安裝程序自動添加的),其他系統默認的是postgres。初始化PostgreSQL的程序如下:
1、初始資料庫。請先用root登陸或者su到root。然後,打命令:
代碼:

# su pgsql
# initdb


正常初始化的應該有以下提示:
引用:

This database system will be initialized with username "pgsql".
This user will own all the data files and must also own the server process.

Creating directory /usr/local/pgsql/data
Creating directory /usr/local/pgsql/data/base
Creating directory /usr/local/pgsql/data/global
Creating directory /usr/local/pgsql/data/pg_xlog
Creating template1 database in /usr/local/pgsql/data/base/1



Success. You can now start the database server using:

/usr/local/bin/postmaster -D /usr/local/pgsql/data
or
/usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start



2、啟動PostgreSQL
代碼:

# /usr/local/etc/rc.d/010.pgsql.sh start


更多詳細的幫助,請看freebsddiary上面的一篇用port來安裝PostgreSQL的文章,全英文。
http://www.freebsddiary.org/postgresql.php

三、設定用戶資料庫。
我是PgSQL的初學者,命令行用得不熟,因而要藉助phpPgAdmin來管理資料庫。
1、先創建一個資料庫,叫做mydb。
2、建立一個數據表叫做ftp,用來存儲用戶名和帳號。這個數據表的結構是pam_pgsql模塊規定的最簡單的表了,每一個欄位都是必須的,你可以擴展這個表的結構,但是不要刪除這些欄位。我導出了一個SQL腳本,方便大家創建。
代碼:

CREATE TABLE "ftp" (
"ID"                int4 DEFAULT nextval('public."ftp_ID_seq"')  NOT NULL ,
"usr"               varchar(32) NOT NULL ,
"pass"              varchar(32) NOT NULL ,
"expired"           bool DEFAULT false  NOT NULL ,
"newtok"            bool DEFAULT false  NOT NULL
);



請創建一些用戶,方便調試:
這是我的ftp表,這些記錄名字都是隨便起的。但請注意只有expired為f(假)的可以成功登陸。
代碼:

ID |   usr   |  pass   | expired | newtok
----+---------+---------+---------+--------
  1 | ftp     | ftp     | f       | f
  2 | ftp1    | ftp1    | t       | t
  4 | ftp3    | ftp3    | f       | f
  6 | go      | abcdef  | f       | f
  3 | ftp2    | ftp2    | f       | f
  5 | downftp | downftp | f       | f



3、創建一個pgsql用戶叫做pamusr,密碼也是pamusr。賦予pamusr對於ftp表的select許可權,注意select就夠了。pam_pgsql只是讀數據表,而不是修改它。你也可以用其他用戶,比如管理PgSQL的pgsql/postgres用戶,但是從安全形度著想,建一個專門提供給pam_pgsql的弱許可權的用戶更好!

備註:
資料庫,數據表,用戶名都不必跟我一樣,pam_pgsql沒有規定,但是這些設定,必須跟pam_pgsql的配置文件/etc/pam_pgsql.conf的一致。

四、設定pam_pgsql模塊:編輯/etc/pam_pgsql.conf
在/etc/pam.conf裡頭加上以上的幾行,更多的資料參考/usr/local/share/doc/pam-pgsql/README
代碼:

#host = 127.0.0.1  這個不需要,默認是本地連接的。如果要連接遠程伺服器,請設置你的IP,並且去掉#
database = mydb
user = pamusr  #剛才添加的訪問PgSQL的用戶
password = pamusr #訪問PgSQL的密碼
table = ftp
user_column = usr     #用戶名在數據表中的欄位
pwd_column = pass     #用戶密碼在數據表中的欄位
expired_column = expired  #用戶是否已經過期的欄位名
newtok_column = newtok    #用戶是否需要修改密碼的欄位



五、設置pam服務。在/etc/pam.conf,加入以下幾項
代碼:

# service-name  module-type     control-flag    module-path  argument

vsftpd    auth          required        pam_pgsql.so  #
vsftpd   account        required        pam_pgsql.so #
vsftpd    password      required        pam_pgsql.so#


注意這裡的service name為vsftpd,這不是必須的。前提是不要跟pam.conf已經有的service name衝突。vsftpd.conf中的pam_service_name一項要跟這裡的service name對應。
關於freebsd-5的PAM的配置
在freebsd-5中的pam配置機制,跟freebsd-4有不同。你應該在/etc/pam.d或者/usr/local/etc/pam.d裡頭建立一個名位vsftpd的文件,內容跟上面的內容一樣。本人在fbsd 5-current上嘗試過配置,但總不成功,無論是pam_pgsql還是pam_mysql,總是提示說找不到這些pam。google了一下,發現這個錯誤好像是fbsd 5-current的bug
http://unix.derkeiler.com/Mailing-Lists/FreeBSD/current/2003-07/0278.html


六、配置vsftpd。這個是參考vsftpd虛擬用戶設置1的官方文檔進行配置的
1、用adduser增加一個用戶,名為virtual。

2、配置/usr/local/etc/vsftpd.conf
代碼:

anonymous_enable=NO
local_enable=YES
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
chroot_local_user=YES
guest_enable=YES
dual_log_enable=YES
guest_username=virtual   #我們剛才增加的本地用戶,虛擬用戶將會享有這個名為virtual本地用戶的許可權。
pam_service_name=vsftpd  # 這個就是我在pam.conf裡頭設置的pam服務的名稱,沒有這一項,vsftpd是用名為ftp的pam服務。
listen=YES
secure_chroot_dir=/usr/local/share/vsftpd/empty   #請加上這一項,vsftpd默認的secure_chroot_dir是/usr/share/empty,用port安裝的話,不會自動創建這個目錄,而是放在/usr/local/share/vsftpd/empty。當然你也可以自己創建一個目錄。



七、調試
用standalone的方法來啟動vsftpd,不要用inetd。
代碼:

/usr/local/libexec/vsftpd
或者
/usr/local/libexec/vsftpd 配置文件名(如vsftpd.conf.1, vsftpd.conf.2)
一般他是搜索/usr/local/etc目錄,如果你放在其他地方就要寫上完整的路徑。


如果沒有沒有出什麼提示證明vsftpd啟動成功。實踐中,我常常出現的錯誤是沒有用root來啟動vsftpd,或者chroot路徑不對。
下面ftp試試
代碼:

> ftp 192.168.1.10
Connected to 192.168.1.10.
220 (vsFTPd 1.2.0)
Name (192.168.1.10:powerplane): downftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.


yeah,成功了。

總結
想要配置vsftpd + 其他的PAM認證方法,本文都可做參考。當然,你可能會修改有關pam.conf的設置了。
freebsd的port裡頭除了有pam_pgsql的模塊以外,還有pam_mysql,pam_ldap的。
一般都是放在/usr/ports/security
《解決方案》

貼一下你的vsftpd.conf配置文件
《解決方案》

我的配置文件,因為不會搞所以全加#了
# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
#local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
#write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
#local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Hello I Love You~~~!!!
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES

#anonymous_enable=NO
#local_enable=YES
#write_enable=NO
#anon_upload_enable=NO
#anon_mkdir_write_enable=NO
#anon_other_write_enable=NO
#chroot_local_user=YES
#guest_enable=YES
#dual_log_enable=YES
#guest_username=virtual
pam_service_name=vsftpd
listen=YES
secure_chroot_dir=/usr/local/share/vsftpd/empty
#connect_from_port_20=YES
background=YES
anon_root=/ftp/ftp

[火星人 ] 求助,vsftp無法添加登錄已經有516次圍觀

http://coctec.com/docs/service/show-post-26313.html