VsFTPd的配置:vsFTPd的运行有两种模式,一种是standalone “initd”模式,另外一种是xinetd模式。
两种模式运行机制不是相同的,stardard initd模式,适合专业FTP,且FTP总是一直有人访问,占用资源也是比较大,如果您的FTP总是有人访问和登入。就要用这种模式。如果您的FTP访问人数比较小,建议您用xinetd模式。xinetd模式,是当用户请求时,vsFTPd才会启动。
不同的环境,当然得用不同的启动模式。
1] 我们主要把vsFTPd的配置文件改一下就行了。配制文件在/etc/vsftpd/vsftpd.conf,用您喜欢的编辑器打开。请参考下面的配置文件。
#Exampleconfigfile/etc/vsftpd.conf
# #Thedefaultcompiledinsettingsareveryparanoid.Thissamplefile #loosensthingsupabit,tomaketheftpdaemonmoreusable. # #AllowanonymousFTP? anonymous_enable=YES # #Uncommentthistoallowlocaluserstologin. local_enable=YES # #UncommentthistoenableanyformofFTPwritecommand. write_enable=YES # #Defaultumaskforlocalusersis077.Youmaywishtochangethisto022, #ifyourusersexpectthat(022isusedbymostotherftpd's) local_umask=022 # #UncommentthistoallowtheanonymousFTPusertouploadfiles.Thisonly #hasaneffectiftheaboveglobalwriteenableisactivated.Also,youwill #obviouslyneedtocreateadirectorywritablebytheFTPuser. #anon_upload_enable=YES # #UncommentthisifyouwanttheanonymousFTPusertobeabletocreate #newdirectories. #anon_mkdir_write_enable=YES # #Activatedirectorymessages-messagesgiventoremoteuserswhenthey #gointoacertaindirectory. dirmessage_enable=YES # #Activateloggingofuploads/downloads. xferlog_enable=YES # #MakesurePORTtransferconnectionsoriginatefromport20(ftp-data). connect_from_port_20=YES # #Ifyouwant,youcanarrangeforuploadedanonymousfilestobeownedby #adifferentuser.Note!Using"root"foruploadedfilesisnot #recommended! #chown_uploads=YES #chown_username=whoever # #Youmayoverridewherethelogfilegoesifyoulike.Thedefaultisshown #below. #xferlog_file=/var/log/vsftpd.log # #Ifyouwant,youcanhaveyourlogfileinstandardftpdxferlogformat xferlog_std_format=YES # #Youmaychangethedefaultvaluefortimingoutanidlesession. #idle_session_timeout=600 # #Youmaychangethedefaultvaluefortimingoutadataconnection. #data_connection_timeout=120 # #Itisrecommendedthatyoudefineonyoursystemauniqueuserwhichthe #ftpservercanuseasatotallyisolatedandunprivilegeduser. #nopriv_user=ftpsecure # #EnablethisandtheserverwillrecogniseasynchronousABORrequests.Not #recommendedforsecurity(thecodeisnon-trivial).Notenablingit, #however,mayconfuseolderFTPclients. #async_abor_enable=YES # #BydefaulttheserverwillpretendtoallowASCIImodebutinfactignore #therequest.TurnonthebelowoptionstohavetheserveractuallydoASCII #manglingonfileswheninASCIImode. #Bewarethatturningonascii_download_enableenablesmaliciousremoteparties #toconsumeyourI/Oresources,byissuingthecommand"SIZE/big/file"in #ASCIImode. #TheseASCIIoptionsaresplitintouploadanddownloadbecauseyoumaywish #toenableASCIIuploads(topreventuploadedscriptsetc.frombreaking), #withouttheDoSriskofSIZEandASCIIdownloads.ASCIImanglingshouldbe #ontheclientanyway.. #ascii_upload_enable=YES #ascii_download_enable=YES # #Youmayfullycustomisetheloginbannerstring: #ftpd_banner=WelcometoblahFTPservice. # #Youmayspecifyafileofdisallowedanonymouse-mailaddresses.Apparently #usefulforcombattingcertainDoSattacks. #deny_email_enable=YES #(defaultfollows) #banned_email_file=/etc/vsftpd.banned_emails # #Youmayspecifyanexplicitlistoflocaluserstochroot()totheirhome #directory.Ifchroot_local_userisYES,thenthislistbecomesalistof #userstoNOTchroot(). #chroot_list_enable=YES #(defaultfollows) #chroot_list_file=/etc/vsftpd.chroot_list # #Youmayactivatethe"-R"optiontothebuiltinls.Thisisdisabledby #defaulttoavoidremoteusersbeingabletocauseexcessiveI/Oonlarge #sites.However,somebrokenFTPclientssuchas"ncftp"and"mirror"assume #thepresenceofthe"-R"option,sothereisastrongcaseforenablingit. #ls_recurse_enable=YES pam_service_name=vsftpd userlist_enable=YES #enableforstandalonemode listen=YES tcp_wrappers=YES
#p#
2]更改完配置文件后,我们可以用下面的命令来重启vsFTPd服务器
[root@linuxsir001root]#/etc/init.d/vsftpdrestart
关闭 vsftpd: [ 确定 ]
为 vsftpd 启动 vsftpd: [ 确定 ]
[root@linuxsir001root]#
3]以匿名方式来访问测试,在text模式下:
注意:在text模式下,要用用户名ftp,密码ftp来访问,这才是在text中匿名访问FTP。看如下的操作:
[root@linuxsir001root]#ftp192.168.0.1
Connectedto192.168.0.1. 220(vsFTPd1.1.3) 530PleaseloginwithUSERandPASS. 530PleaseloginwithUSERandPASS. KERBEROS_V4rejectedasanauthenticationtype Name(192.168.0.1:root):ftp这里写上ftp 331Pleasespecifythepassword. Password:[这里添写ftp的密码],匿名登入密码也是ftp 230Loginsuccessful.Havefun. RemotesystemtypeisUNIX. Usingbinarymodetotransferfiles. ftp>ls 227EnteringPassiveMode(192,168,0,1,137,151) 150Herecomesthedirectorylisting. drwxr-xr-x6004096May2513:54RedHat90 drwxr-xr-x2004096Feb2819:21pub 226DirectorysendOK. ftp>
那匿名用户所访问的是哪个目录?是/var/ftp这个目录
出现问题的解决:有时出错,是因为没有ftp和nobody用户,所以要在系统中添加这两个用户,一般的情况下,这两个用户在系统中是存在的。看下面的操作。
[root@linuxsir001root]#adduserftp
adduser:userftpexists [root@linuxsir001root]#addusernobody adduser:usernobodyexists
从上面的操作中可知ftp和nobody用户是存在的,所以没有必要添加ftp和nobody用户了。如果不存在,一定要添加这两个用户,否则会出现匿名用户不能访问的情况。
4]如果要以系统中存在的普通用户登入FTP,也没有什么可以设置的,添加一个用户就行。比如我要添加beinan这个用户,就要用下面的办法
[root@linuxsir001root]#adduserbeinan
[root@linuxsir001root]#passwdbeinan Changingpasswordforuserbeinan. Newpassword: BADPASSWORD:itdoesnotcontainenoughDIFFERENTcharacters Retypenewpassword: passwd:allauthenticationtokensupdatedsuccessfully. [root@linuxsir001root]#
这样的话,就在/home目录中出现一个beinan的用户目录:如下:
[root@linuxsir001root]#ls/home/
beinan
如果我们想让beinan这个用户作为虚拟用户,也就是说,beinan这个用户是不能登入系统的,只能是登入FTP。 那这样的用户应该如何添加呢??
[root@linuxsir001backupNow]#adduser-gftp-s/sbin/nologinbeinan
[root@linuxsir001backupNow]#passwdbeinan Changingpasswordforuserbeinan. Newpassword: Retypenewpassword: passwd:allauthenticationtokensupdatedsuccessfully. [root@linuxsir001backupNow]#
注:这仅仅是vsFTPd添加虚拟用户的一个方法,还有更好的办法需要我们去学习!另外的办法也在测试之中。严格上来说,这种办法不能算虚拟用户。还有另外的一个办法,就是通过pam认证,用db_load来添加用户,目前我也弄成功了,不过相对要复杂一点。正在测试之中。
如果我们想把用户目录定位到别的目录应该怎么办呢??这个也比较简单,看一下useradd就比较明白了。比如我想添加beinan这个用户,并把目录放在/opt目录中:如下操作:
[root@linuxsir001root]#adduser-d/opt/beinanbeinan
[root@linuxsir001root]#passwdbeinan Changingpasswordforuserbeinan. Newpassword: Retypenewpassword: passwd:allauthenticationtokensupdatedsuccessfully.
如果是添加虚拟用户,也就是不让用户登入系统,只能登入FTP的用户。如果我们想把beinan这个用户目录定位在/opt/beinan这个目录中,根据上面的方法。我们应该如下操作
[root@linuxsir001backupNow]#adduser-d/opt/beinan-gftp-s/sbin/nologinbeinan
[root@linuxsir001backupNow]#passwdbeinan Changingpasswordforuserbeinan. Newpassword: Retypenewpassword: passwd:allauthenticationtokensupdatedsuccessfully. [root@linuxsir001backupNow]#
看一下是不是已经成功添加到了beinan这个用户,并把beinan的家目录放在了/opt目录中呢??
[root@linuxsir001root]#ls/opt/
beinan
证明已经成功。
#p#
我们可以在text模式下以beinan用户登入,然后来访问ftp。
[root@linuxsir001root]#ftp192.168.0.1
Connectedto192.168.0.1. 220(vsFTPd1.1.3) 530PleaseloginwithUSERandPASS. 530PleaseloginwithUSERandPASS. KERBEROS_V4rejectedasanauthenticationtype Name(192.168.0.1:root):beinan 331Pleasespecifythepassword. Password: 230Loginsuccessful.Havefun. RemotesystemtypeisUNIX. Usingbinarymodetotransferfiles. ftp>
是不是成功了呢?
我们也可以用gftp来访问beinan用户,并上传相应的东西,所传上的东西就放在beinan用户所在的家目录中,普通用户的家目录在哪里,写您所用的添加用户的方法有关。我在前面已经说了两种办法,一种是默认的添加方法,就是放在/home目录中。
在本例中,我是采用默认的添加用户的方法。也就是不特别指定用户用户,这样的话,用户目录就在/home目录中。比如用beinan登入FTP时,访问的就是/home/beinan这个目录。让传的东西也在这个目录中。匿名用户所访问是:/var/ftp这个目录。