linux搭建ftp服务
一、检查防火墙策略
ftp走21和22端口,很多时候都是因为防火墙策略问题倒置不能正常使用,所以先进行防火墙检查,关闭防火墙或者在开启的的防火墙中放行21,22端口(防火墙一般默认放行22端口)
关闭防火墙操作如下:
linux6: 防火墙状态: service iptables status 关闭防火墙: service iptables stop 禁用防火墙: chkconfig iptables off linux7: 防火墙状态: systemctl status firewalld.service 关闭防火墙: systemctl stop firewalld.service 禁用防火墙: systemctl disable firewalld.service
防火墙放行端口操作如下:
1、防火墙放行21端口: iptables -I INPUT 5 -p tcp --dport 21 -j ACCEPT #要先启动ftp服务,然后在防火墙中放行端口,在重启防火墙 2、查看21端口状态: netstat -na --ip|grep 21 #这时候可能还看不见,因为ftp服务没有启动 3、防火墙添加ftp模块: vi /etc/sysconfig/iptables-config 添加以下内容: IPTABLES_MODULES="ip_nat_ftp ip_conntrack_ftp" 4、重启防火墙: linux6: service iptables restart linux7: firewall-cmd --reload 5、查看防火墙端口规则 iptables -nL --line-number
客户端可以使用nc命令测试fpt服务器端口
nc -v 192.168.27.10 21
二、安装ftp
1、检查ftp服务是否安装
rpm -qa|grep ftp
2、在服务端安装软件vsftp(已经配置了本地yum源)
yum install -y vsftpd.x86_64
3、在客户端安装软件ftp(已经配置了本地yum源)
yum install -y ftp
三、启动ftp服务端并修改配置文件
1、服务端启动vsftp
linux6: service vsftpd start linux7: systemctl start vsftp.service
# setsebool -P ftpd_use_fusefs on # sestatus -b | grep ftp allow_ftpd_anon_write off allow_ftpd_full_access off allow_ftpd_use_cifs off allow_ftpd_use_nfs off ftp_home_dir on ftpd_connect_db off ftpd_use_fusefs off ftpd_use_passive_mode off httpd_enable_ftp_server off tftp_anon_write off tftp_use_cifs off tftp_use_nfs off
特别注意:默认ftp服务器是不允许root用户直接访问的,也强烈不建议这么做,若有特殊要求必须使用root用户访问ftp服务器,操作如下
修改服务器端配置文件 vi /etc/vsftpd/ftpusers 注释root vi /etc/vsftpd/user_list 注释root service vsftpd restart
selinux在启动状态下是不允许root用户直接登录ftp服务端,需将selinux关闭即可
四、使用ftp进行下载和上传测试
建议专门建一个用户使用ftp
上传测试:
# ftp 192.168.27.10 #连接ftp服务端 Connected to 192.168.27.10 (192.168.27.10). 220 (vsFTPd 2.2.2) Name (192.168.27.10:root): root #输入登录ftp服务端的用户 331 Please specify the password. Password: #输入用户密码 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> put test.txt #上传文件到ftp服务端,此步可以cd进入ftp服务端的某一个目录,默认就是ftp用户的home目录 local: shuaige remote: shuaige 227 Entering Passive Mode (192,168,27,10,42,185). 150 Ok to send data. 226 Transfer complete. ftp>
下载测试:
# ftp 192.168.27.10 #连接ftp服务端 Connected to 192.168.27.10 (192.168.27.10). 220 (vsFTPd 2.2.2) Name (192.168.27.10:root): root #输入登录ftp服务端的用户 331 Please specify the password. Password: #输入用户密码 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> dir #查看当前目录 227 Entering Passive Mode (192,168,27,10,78,212). 150 Here comes the directory listing. -rw-r--r-- 1 1100 1100 0 Nov 06 08:09 lihua 226 Directory send OK. ftp> get lihua #下载文件(存放在ftp连接时当前所在目录) local: lihua remote: lihua 227 Entering Passive Mode (192,168,27,10,75,193). 150 Opening BINARY mode data connection for lihua (0 bytes). 226 Transfer complete. ftp>
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/203193.html原文链接:https://javaforall.net
