如何在 CentOS 7 中安裝和配置 FTP 伺服器
在本文中,我們將學習如何使用“vsftpd”在CentOS 7上配置FTP伺服器。“vsftpd”(Very Secure File Transport Protocol Daemon)是Linux系統上一個安全且快速的FTP伺服器。
安裝“vsftpd”
以下是安裝“vsftpd”的命令,需要使用root使用者執行以下命令。
# yum install vsftp ftp –y Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in Setting up Install Process No package vsftp available. Resolving Dependencies --> Running transaction check ---> Package ftp.x86_64 0:0.17-54.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================= Package Arch Version Repository Size ================================================================================================================================================================================= Installing: vsftpd x86_64 2.2.2-21.el6 base 155 k ftp x86_64 0.17-54.el6 base 58 k Transaction Summary ================================================================================================================================================================================= Install 2 Package(s) Total download size: 58 k Installed size: 95 k Is this ok [y/N]: y Downloading Packages: ftp-0.17-54.el6.x86_64.rpm , vsftpd-2.2.2-21.el6.x86_64.rpm | 58 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : ftp-0.17-54.el6.x86_64 Installing : vsftpd-2.2.2-21.el6.x86_64 Verifying : vsftpd-2.2.2-21.el6.x86_64 Verifying : ftp-0.17-54.el6.x86_64 Installed: ftp.x86_64 0:0.17-54.el6, vsftpd.x86_64 0:2.2.2-21.el6 Complete!
配置“vsftpd”
我們需要編輯“vsftpd”配置檔案來保護FTP伺服器,因為預設情況下它允許匿名使用者登入並使用伺服器。
# vi /etc/vsftpd/vsftpd.conf
我們必須禁止匿名使用者透過FTP訪問檔案;將anonymous_enable設定更改為NO。
anonymous_enable=NO
允許本地使用者登入,將local_enable設定更改為YES。
local_enable=YES
如果要允許本地使用者寫入目錄,則將配置檔案中的write_enable設定更改為YES。
write_enable=YES
本地使用者將被“chroot監禁”,並且將拒絕他們訪問伺服器的任何其他部分;將配置檔案中的chroot_local_user設定更改為YES。
chroot_local_user=YES
以下是一個簡單的配置檔案,供您參考:
anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 chroot_local_user=YES dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=YES #listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES Save the file with the command :wq .
重啟vsftpd服務
我們需要重啟“vsftpd”服務,以便應用配置更改。
# systemctl restart vsftpd
我們將設定“vsftpd”服務在啟動時啟動,以下是啟用“vsftpd”啟動的命令。
# systemctl enable vsftpd
允許“vsftpd”透過防火牆
我們必須允許預設FTP埠(埠21)透過防火牆。
# firewall-cmd --permanent --add-port=21/tcp
我們需要重新載入防火牆。
# firewall-cmd –reload
建立FTP使用者
我們將建立除本地使用者之外的FTP使用者並分配主目錄。
在本教程中,我將建立一個沒有主目錄的使用者,因此我使用–M而不是–m。
# useradd -M user1 –s /sbin/nologin # passwd user1
接下來,我們將透過建立一個新目錄來設定“user1”的主目錄。
# mkdir /var/www/mike # chmod 755 /var/www/mike
我們必須為FTP上的“user1”提供訪問許可權。
# chown -R mike /var/www/user1 We can access the FTP server from the client on your favorite browser using the url ftp://192.168.100.108
使用以上資訊,我們可以輕鬆地配置和安裝FTP伺服器。“vsftpd”是一個簡單且非常安全的FTP伺服器,我們可以使用本地使用者,也可以建立其他使用者專門用於FTP“vsftpd”伺服器,它還有許多其他功能。
廣告