在CentOS上配置vsftpd(Very Secure FTP Daemon)作為FTP服務器涉及幾個關鍵步驟,包括安裝、配置、啟動服務、配置防火墻、創建用戶以及測試連接。以下是詳細的步驟:
首先,確保你的CentOS系統已經更新到最新版本,然后使用以下命令安裝vsftpd:
sudo yum update -y
sudo yum install vsftpd -y
安裝完成后,需要編輯vsftpd的配置文件 /etc/vsftpd/vsftpd.conf
。你可以使用文本編輯器(如 vi
或 nano
)打開并編輯該文件:
sudo vi /etc/vsftpd/vsftpd.conf
根據需要進行以下配置:
listen=YES
:啟用獨立模式,監聽端口21。listen_ipv6=NO
:禁用IPv6支持(如果不需要)。anonymous_enable=NO
:禁止匿名用戶登錄。local_enable=YES
:允許本地用戶登錄。write_enable=YES
:允許FTP寫操作。chroot_local_user=YES
:將本地用戶鎖定在其主目錄中。allow_writeable_chroot=YES
:允許chroot目錄可寫(如果需要)。userlist_enable=YES
:啟用用戶列表。userlist_file=/etc/vsftpd/user_list
:用戶列表文件路徑。userlist_deny=NO
:如果用戶列表文件存在,則允許列表中的用戶登錄。確保防火墻允許FTP流量。CentOS 7及以上版本使用 firewalld
:
sudo firewall-cmd --permanent --add-service=ftp
sudo firewall-cmd --permanent --add-port=21/tcp
sudo firewall-cmd --permanent --add-port=20/tcp
sudo firewall-cmd --reload
創建一個用于FTP訪問的用戶,并設置密碼:
sudo useradd ftpuser
sudo passwd ftpuser
按照提示輸入密碼。
使用FTP客戶端(如FileZilla)連接到你的服務器,測試是否可以正常登錄和傳輸文件。例如:
確保vsftpd配置文件中沒有啟用不必要的選項。
使用SSL/TLS加密FTP連接(可選但推薦):
sudo yum install vsftpd-ssl -y
編輯 /etc/vsftpd/vsftpd.conf
,添加或修改以下配置項:
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
rsa_cert_file=/etc/pki/tls/certs/localhost.crt
rsa_private_key_file=/etc/pki/tls/private/localhost.key
重啟vsftpd服務:
sudo systemctl restart vsftpd