CentOS7搭建FTP服務器和安裝FTP客戶端
一、概述
項目需要搭建文件FTP服務器,基于Centos7搭建FTP服務器,同樣再CentOS另外一臺服務器安裝FTP客戶端,測試服務端的大家情況;其他就不多說了,介紹下大家流程,FTP服務器端用的軟件版本:version 3.0.2;FTP服務端分為主動模式和被動模式;主動模式,就是客戶端提供端口,ftp服務端連接客戶端提供的端口,實現數據推送;被動模式,ftp服務器提供端口給客戶端,客戶端主動連ftp服務器;
二、FTP服務器安裝
1.1、安裝vsftpd
yum -y install vsftpd
1.2、修改配置文件
按照下面修改配置文件
cd /etc/vsftpd
vim vsftpd.conf
配置文件:
# 禁用匿名模式 anonymous_enable=NO # # When SELinux is enforcing check for SE bool ftp_home_dir local_enable=YES # #具有寫權限 write_enable=YES # #本地用戶創建文件或目錄的掩碼 local_umask=022 # Activate directory messages - messages given to remote users when they dirmessage_enable=YES # #當設定為YES時,使用者上傳與下載日志都會被紀錄起來。記錄日志與下一個xferlog_file設定選項有關 xferlog_enable=YES xferlog_std_format=YES
xferlog_file=/var/log/xferlog # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES #chown_uploads=YES #chown_username=whoever #idle_session_timeout=600 # #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 # # async_abor_enable=YES # # ASCII mangling is a horrible feature of the protocol. ascii_upload_enable=NO ascii_download_enable=NO # # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. # # 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 chroot_local_user=YES chroot_list_enable=YES # (default follows)-該文件記得要有相應用戶讀寫權限 chroot_list_file=/etc/vsftpd/chroot_list #chroot_list_file=/data/ftp/ #ls_recurse_enable=YES # #listen=NO # # Make sure, that one of the listen options is commented !! #listen_ipv6=YES
pam_service_name=vsftpd userlist_enable=NO tcp_wrappers=YES allow_writeable_chroot=YES listen_port=8887 #FTP訪問目錄 local_root=/data/ftp/
#被動模
pasv_enable=YES #被動模式對外提供端口 pasv_min_port=65400 pasv_max_port=65410
1.3、新建用戶和賦值權限
#新建用戶 useradd ftptrm -s /sbin/nologin -d /data/ftp #修改密碼 passwd ftptrm #修改權限 chown -R ftptrm /data/ftp chmod o+w ftptrm /data/ftp #修改用戶 echo 'ftptrm' >> /etc/vsftpd/user_list
cp /etc/vsftpd/user_list /etc/vsftpd/chroot_list
#服務器的selinux被禁用
vim /etc/pam.d/vsftpd
注釋掉如下內容
#auth required pam_shells.so
1.4、防火墻關閉(對外提供端口8887、65400-65410
systemctl stop firewalld firewall-cmd --permanent --zone=public --add-port=8887/tcp firewall-cmd --permanent --zone=public --add-port=65400-65410/tcp firewall-cmd --reload #重新加載
firewall-cmd --zone=public --list-port #參考開發端口
#firewall-cmd --permanent --zone=public --remove-port=8886/tcp #禁用端口
1.5、啟動服務
#開機啟動
systemctl enable vsftpd.service
#重啟服務
systemctl restart vsftpd.service
#啟動
systemctl start vsftpd.service
#停止
systemctl stop vsftpd.service
#狀態
systemctl status vsftpd.service
三、FTP客戶端安裝
ftp安裝
yum -y install ftp
客戶端連接命令
#連接 IP 端口 ftp 192.168.1.100 8887 #輸入名稱 ftp>name #密碼 ftp>password #進入目錄 ftp>cd /data/ftp #下載本地 ftp>get test.txt
#文件上傳
ftp>put myfile /data/ftp/
530 Permission denied。
vsftpd.ftpusers:位于/etc/vsftpd目錄下。它指定了哪些用戶賬戶不能訪問FTP服務器,例如root等。
553 Could not create file.
賦值文件夾的權限:chmod -R 777

浙公網安備 33010602011771號