Centos7 ftp環境搭建,centos7ftp搭建
沒玩過linux,折騰了半天的ftp,好不容易親測通過了。不容易啊。
作業環境:vm虛擬機器 centos7
首先:搞定網路問題;預設情況下使用ifconfig可以看到虛擬機器下是無網路的。(註:虛擬機器網路設定為NAT或橋接模式都是可以的)
輸入命令nmtui 開啟網路設定
斷行符號-》斷行符號
將倒數第二項 Automatically connect 勾上 然後就有網路了
然後更新系統:yum update
查看vsftpd是否已安裝:vsftpd -v (預設都是沒安裝的)
安裝vsftpd:yum install vsftpd
然後 y y y......
安裝完成後配置防火牆(firewall)
firewall-cmd --permanent --add-service=ftp
firewall-cmd --add-port=21/tcp
firewall-cmd --reload
配置vsftpd: vi /etc/vsftpd/vsftpd.conf
開啟並設定以下配置:
anonymous_enable=NO (修改)
chroot_local_user=YES (取消注釋)(此項為限定使用者訪問目錄為目前的目錄)
然後最底部設定並添加:
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
listen_port=21
data_connection_timeout=12
guest_enable=YES
guest_username=ftpuser (ftp的使用者名稱,多個使用者可重複這一行並修改使用者名稱)
user_config_dir=/usr/website(使用者訪問的檔案夾)
pasv_enable=YES
virtual_use_local_privs=YES
pasv_min_port=10060
pasv_max_port=10090
accept_timeout=5
connect_timeout=1
allow_writeable_chroot=YES (解決串連是提示500 OOPS:vsftpd:refusing to run with writable root inside chroot() 的問題)
退出並儲存:wq
重啟vsftpd:
systemctl restart vsftpd.service
相關命令:systemctl start vsftpd.service
systemctl status vsftpd.service
建立檔案夾: mkdir /usr/website
建立使用者:
useradd -g root -M -d /usr/website -s /sbin/nologin ftpuser
設定密碼:
passwd ftpuser
檔案夾授權:
chown -R ftpuser.root /usr/website
到目前為止,還有最後一個問題:selinux (不設定的情況下ftp提示:553 Could not create file)
搗鼓了半天都沒配置成功。最後嘗試了兩個方案。
一、關閉selinux;
vi /etc/selinux/config
設定 SELINUX=Disabled
重啟系統。
二、將selinux改成permissive(寬容模式)
命令:setenforce 0
然後,可以試試看了。