Ubuntu16.04环境下搭建FTP服务器的教程
Ubuntu16.04搭建FTP服务器
安装ftp
安装ftp:
sudoapt-getupdate sudoapt-getinstallvsftpd
检查ftp是否安装:
vsftpd--version
更改配置文件
注意使用sudo命令获得root权限
打开配置文件:
sudovim/etc/vsftpd.conf
做如下更改:
#Exampleconfigfile/etc/vsftpd.conf # #Thedefaultcompiledinsettingsarefairlyparanoid.Thissamplefile #loosensthingsupabit,tomaketheftpdaemonmoreusable. #Pleaseseevsftpd.conf.5forallcompiledindefaults. # #READTHIS:ThisexamplefileisNOTanexhaustivelistofvsftpdoptions. #Pleasereadthevsftpd.conf.5manualpagetogetafullideaofvsftpd's #capabilities. # # #Runstandalone?vsftpdcanruneitherfromaninetdorasastandalone #daemonstartedfromaninitscript. listen=NO # #ThisdirectiveenableslisteningonIPv6sockets.Bydefault,listening #ontheIPv6"any"address(::)willacceptconnectionsfrombothIPv6 #andIPv4clients.Itisnotnecessarytolistenon*both*IPv4andIPv6 #sockets.Ifyouwantthat(perhapsbecauseyouwanttolistenonspecific #addresses)thenyoumustruntwocopiesofvsftpdwithtwoconfiguration #files. listen_ipv6=YES # #AllowanonymousFTP?(Disabledbydefault). anonymous_enable=NO # #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 # #Ifenabled,vsftpdwilldisplaydirectorylistingswiththetime #inyourlocaltimezone.ThedefaultistodisplayGMT.The #timesreturnedbytheMDTMFTPcommandarealsoaffectedbythis #option. use_localtime=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. #Notethatthedefaultlogfilelocationis/var/log/xferloginthiscase. 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. #BewarethatonsomeFTPservers,ASCIIsupportallowsadenialofservice #attack(DoS)viathecommand"SIZE/big/file"inASCIImode.vsftpd #predictedthisattackandhasalwaysbeensafe,reportingthesizeofthe #rawfile. #ASCIImanglingisahorriblefeatureoftheprotocol. #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 # #Youmayrestrictlocaluserstotheirhomedirectories.SeetheFAQfor #thepossiblerisksinthisbeforeusingchroot_local_useror #chroot_list_enablebelow. #chroot_local_user=YES # #Youmayspecifyanexplicitlistoflocaluserstochroot()totheirhome #directory.Ifchroot_local_userisYES,thenthislistbecomesalistof #userstoNOTchroot(). #(Warning!chroot'ingcanbeverydangerous.Ifusingchroot,makesurethat #theuserdoesnothavewriteaccesstothetopleveldirectorywithinthe #chroot) chroot_local_user=YES 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 # #Customization # #Someofvsftpd'ssettingsdon'tfitthefilesystemlayoutby #default. # #Thisoptionshouldbethenameofadirectorywhichisempty.Also,the #directoryshouldnotbewritablebytheftpuser.Thisdirectoryisused #asasecurechroot()jailattimesvsftpddoesnotrequirefilesystem #access. secure_chroot_dir=/var/run/vsftpd/empty # #ThisstringisthenameofthePAMservicevsftpdwilluse. pam_service_name=ftp # #ThisoptionspecifiesthelocationoftheRSAcertificatetouseforSSL #encryptedconnections. rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key ssl_enable=NO # #Uncommentthistoindicatethatvsftpduseautf8filesystem. utf8_filesystem=YES
退出编辑模式后,使用:wq保存退出vim.
创建ftp用户
此处的操作需要使用root权限,若操作被拒绝,使用sudo:
sudomkdir/home/ftpdir sudouseraddftpdir-d/home/ftpdir-m sudopasswdftpdir sudomkdir/home/ftpdir/ftp sudochmod777-R/home/ftpdir/ftp usermod-s/sbin/nologinftpdir
配置完成后,添加用户:
sudovim/etc/vsftpd.chroot_list
将ftpdir添加在文件中。
ftpdir
到此为止,整个ftp的搭建过程就完成了,接下来就是关于如何去使用了。
启动或者重启ftp
启动或者重启ftp:
servicevsftpdstartservicevsftpdrestart
查看ftp状态:
servicevsftpdstatus
若要关闭ftp服务,可以使用如下命令:
servicevsftpdstop
查看服务器ip
打开命令端
robot@robot:~$ifconfig enp4s0f2Linkencap:EthernetHWaddr74:d0:2b:ec:fa:f9 UPBROADCASTMULTICASTMTU:1500Metric:1 RXpackets:0errors:0dropped:0overruns:0frame:0 TXpackets:0errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:0(0.0B)TXbytes:0(0.0B) loLinkencap:LocalLoopback inetaddr:127.0.0.1Mask:255.0.0.0 inet6addr:::1/128Scope:Host UPLOOPBACKRUNNINGMTU:65536Metric:1 RXpackets:12840errors:0dropped:0overruns:0frame:0 TXpackets:12840errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:1174976(1.1MB)TXbytes:1174976(1.1MB) wlp3s0Linkencap:EthernetHWaddr24:fd:52:85:42:0c inetaddr:192.168.1.110Bcast:192.168.1.255Mask:255.255.255.0 inet6addr:fe80::c13c:b38e:69c7:cdf2/64Scope:Link UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1 RXpackets:99764errors:0dropped:0overruns:0frame:0 TXpackets:95225errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:98718687(98.7MB)TXbytes:14326894(14.3MB)
由于此处连接的是wifi,因此在wlp3s0这里找到对应的ip地址为192.168.1.110(如果连接网线则在第一段找ip,每台电脑的配置都不一样,可根据实际情况考虑)
登陆
使用filezilla或者打开文件管理器输入ftp://ipaddress
打开计算机,输入服务器的ip地址ftp://192.168.1.110
输入用户名和密码,此处使用的用户名为ftpdir,密码为123456
最后就可以看到服务器上的创建的文件夹了。
ubuntu上文件位置
在完成ftp服务器的搭建和测试工作后,文件存放在服务哪里呢,怎么找到这些文件?
在创建用户那一节,在/home目录这里创建了ftpdir文件夹,ftpdir文件夹里创建了一个可读可写的文件夹ftp,在之后的文件传输中,可以切换到ftp文件夹中寻找文件,此处操作需要使用sudo获取权限。
robot@robot:~$cd/home/ftpdir/ftp robot@robot:/home/ftpdir/ftp$ls 魔方.zip
至此,整个过程就结束了,在搭建的过程中,参考了网上其他前辈的经验,这仅作为学习之路上的笔记,所提到的东西若有错误,欢迎各位指出!
总结
以上所述是小编给大家介绍的Ubuntu16.04环境下搭建FTP服务器的教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。