1. 程式人生 > 其它 >CentOS7搭建FTP伺服器和安裝FTP客戶端

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

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 

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等。