centos7.4搭建ftp服務器

1. 準備環境

版本 說明
CentOS Linux release 7.4.1708 (Core) cat /etc/redhat-release

2.檢查是否已安裝vsftpd

[root@node1 opt]# rpm -qa|grep vsftpd

如果沒有則通過yarm源進行安裝

3.安裝配置

yum install -y vsftpd

在這裏插入圖片描述
進入到ftp的根目錄默認是/etc/vsftpd/文件中進行配置
在這裏插入圖片描述

[root@htuidc ~]# tree /etc/vsftpd/

/etc/vsftpd/

├── chroot_list #自建的允許切換用戶清單

├── ftpusers  #ftpusers配置文件,在裏面的用戶禁止使用ftp登陸

├── user_list #文件禁止登錄FTP的用戶

├── vsftpd.conf #主配置文件

└── vsftpd_conf_migrate.sh
/etc/vsftpd/vsftpd.conf:vsftpd 的核心配置文件

/etc/vsftpd/ftpusers:用於指定哪些用戶不能訪問FTP 服務器。  黑名單

/etc/vsftpd/user_list:指定允許使用vsftpd 的用戶列表文件。  白名單

/etc/vsftpd/chroot_list:指定允許使用vsftpd 的用戶列表文件。  控制名單下的目錄能不能離開ftp根目錄

vsftpd.conf具體配置如下:

anonymous_enable=NO  #允許匿名用戶訪問爲了安全選擇關閉
local_enable=YES   # 允許本地用戶登錄
write_enable=YES   # 是否允許寫入
local_umask=022  # 本地用戶上傳文件的umask
dirmessage_enable=YES #爲YES則進入目錄時顯示此目錄下由message_file選項指定的文本文件(,默認爲.message)的內容
xferlog_enable=YES #開啓日誌

xferlog_std_format=YES #標準格式
connect_from_port_20=YES
xferlog_file=/var/log/xferlog   #ftp日誌目錄

idle_session_timeout=6000 #設置客戶端連接時間

data_connection_timeout=1200 #設置數據連接時間 針對上傳,下載
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list #設置爲YES則下面的控制有效
chroot_list_enable=YES #若爲NO,則記錄在chroot_list_file所指定的文件(默認是/etc/vsftpd.chroot_list)中的用戶將被chroot在登錄後所在目錄中,無法離開.如果爲YES,則所記錄的用戶將不被chroot.這裏YES.
chroot_local_user=YES
userlist_deny=NO #若設置爲YES則記錄在userlist_file選項指定文件(默認是/etc/vsftpd.user_list)中的用戶將無法login,並且將檢察下面的userlist_deny選項
userlist_enable=YES #若爲NO,則僅接受記錄在userlist_file選項指定文件(默認是/etc/vsftpd.user_list)中的用戶的login請求.若爲YES則不接受這些用戶的請求.
userlist_file=/etc/vsftpd/user_list #白名單
chroot_list_enable=YES
local_root=/var/ftp/pub #根目錄
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

3、創建白名單

useradd  xxx passwd xxx 並添加到user_list和chroot_list中去

4、關閉防火牆

systemctl stop firewalld.service  

5.啓動ftp服務器

systemctl enable vsftpd.service  #開機自啓
systemctl restart vsftpd.service #啓動

6.賦權,將ftp指定的根目錄賦權爲777權限

chmod 777 /var/ftp/pub

在這裏插入圖片描述
運行以下命令查看 FTP 服務端口

[root@node1 sbin]# netstat -antup|grep ftp
tcp6       0      0 :::21                   :::*                    LISTEN      24196/vsftpd        
[root@node1 sbin]# 

配置本地用戶登錄

4.文件解決

Unregistered Authentication Agent for unix-process

[root@node1 sbin]# journalctl -xe
-- Unit session-98.scope has finished starting up.
-- 
-- The start-up result is done.
Jul 01 00:01:02 node1.bigdata.com CROND[24151]: (root) CMD (run-parts /etc/cron.hourly)
Jul 01 00:01:02 node1.bigdata.com systemd[1]: Starting Session 98 of user root.
-- Subject: Unit session-98.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-98.scope has begun starting up.
Jul 01 00:01:02 node1.bigdata.com run-parts(/etc/cron.hourly)[24154]: starting 0anacron
Jul 01 00:01:02 node1.bigdata.com anacron[24160]: Anacron started on 2020-07-01
Jul 01 00:01:02 node1.bigdata.com anacron[24160]: Normal exit (0 jobs run)
Jul 01 00:01:02 node1.bigdata.com run-parts(/etc/cron.hourly)[24162]: finished 0anacron
Jul 01 00:02:59 node1.bigdata.com polkitd[627]: Registered Authentication Agent for unix-process:24169:4815557 (system bus name :1.221 [/usr/bin/pkttyage
Jul 01 00:02:59 node1.bigdata.com systemd[1]: Starting Vsftpd ftp daemon...
-- Subject: Unit vsftpd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit vsftpd.service has begun starting up.
Jul 01 00:02:59 node1.bigdata.com polkitd[627]: Unregistered Authentication Agent for unix-process:24169:4815557 (system bus name :1.221, object path /or
Jul 01 00:02:59 node1.bigdata.com systemd[1]: vsftpd.service: control process exited, code=exited status=2
Jul 01 00:02:59 node1.bigdata.com systemd[1]: Failed to start Vsftpd ftp daemon.
-- Subject: Unit vsftpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit vsftpd.service has failed.
-- 
-- The result is failed.
Jul 01 00:02:59 node1.bigdata.com vsftpd[24175]: 500 OOPS: run two copies of vsftpd for IPv4 and IPv6
Jul 01 00:02:59 node1.bigdata.com systemd[1]: Unit vsftpd.service entered failed state.
Jul 01 00:02:59 node1.bigdata.com systemd[1]: vsftpd.service failed.

500 OOPS: run two copies of vsftpd for IPv4 and IPv6

#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
#一定要關掉,因爲下面ipv6已經包含了
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
#確保,註釋掉了一個listen選項
listen_ipv6=YES

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