CentOS7安裝和配置FTP

1. 安裝vsftpd

#安裝vsftpd
yum install -y vsftpd
#設置開機啓動
systemctl enable vsftpd.service 
# 重啓
service vsftpd restart
# 查看vsftpd服務的狀態
systemctl status vsftpd.service
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2. 配置vsftpd.conf

#備份配置文件 
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

#執行以下命令
sed -i "s/anonymous_enable=YES/anonymous_enable=NO/g" '/etc/vsftpd/vsftpd.conf'

sed -i "s/#anon_upload_enable=YES/anon_upload_enable=NO/g" '/etc/vsftpd/vsftpd.conf'

sed -i "s/#anon_mkdir_write_enable=YES/anon_mkdir_write_enable=YES/g" '/etc/vsftpd/vsftpd.conf'

sed -i "s/#chown_uploads=YES/chown_uploads=NO/g" '/etc/vsftpd/vsftpd.conf'

sed -i "s/#async_abor_enable=YES/async_abor_enable=YES/g" '/etc/vsftpd/vsftpd.conf'

sed -i "s/#ascii_upload_enable=YES/ascii_upload_enable=YES/g" '/etc/vsftpd/vsftpd.conf'

sed -i "s/#ascii_download_enable=YES/ascii_download_enable=YES/g" '/etc/vsftpd/vsftpd.conf'

sed -i "s/#ftpd_banner=Welcome to blah FTP service./ftpd_banner=Welcome to FTP service./g" '/etc/vsftpd/vsftpd.conf'

#添加下列內容到vsftpd.conf末尾
use_localtime=YES
listen_port=21
chroot_local_user=YES
idle_session_timeout=300
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd/vconf
data_connection_timeout=1
virtual_use_local_privs=YES
pasv_min_port=10060
pasv_max_port=10090
accept_timeout=5
connect_timeout=1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

3. 建立用戶文件

#第一行用戶名,第二行密碼,不能使用root爲用戶名
vi /etc/vsftpd/virtusers
chris
123456
chang
123456
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4. 生成用戶數據文件

db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db

#設定PAM驗證文件,並指定對虛擬用戶數據庫文件進行讀取

chmod 600 /etc/vsftpd/virtusers.db 
  • 1
  • 2
  • 3
  • 4
  • 5

5. 修改/etc/pam.d/vsftpd文件

# 修改前先備份 

cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak

# 將auth及account的所有配置行均註釋掉
vi /etc/pam.d/vsftpd

auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers

account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers

# 如果系統爲32位,上面改爲lib
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

6. 新建系統用戶vsftpd,用戶目錄爲/home/vsftpd

#用戶登錄終端設爲/bin/false(即:使之不能登錄系統)
useradd vsftpd -d /home/vsftpd -s /bin/false
chown -R vsftpd:vsftpd /home/vsftpd
  • 1
  • 2
  • 3

7.建立虛擬用戶個人配置文件

mkdir /etc/vsftpd/vconf
cd /etc/vsftpd/vconf

#這裏建立兩個虛擬用戶配合文件
touch chris chang

#建立用戶根目錄
mkdir -p /home/vsftpd/chris/

#編輯chris用戶配置文件,內容如下,其他用戶類似
vi chris

local_root=/home/vsftpd/chris/
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

8. 防火牆設置

vi /etc/sysconfig/iptables
#編輯iptables文件,添加如下內容,開啓21端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
  • 1
  • 2
  • 3
  • 4

9. 重啓vsftpd服務器

service vsftpd restart
  • 1

10. 使用xftp等軟件連接測試

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章