前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >centos7下搭建ftp服务器

centos7下搭建ftp服务器

作者头像
dogfei
发布2020-07-31 11:25:07
2.6K0
发布2020-07-31 11:25:07
举报
文章被收录于专栏:devops探索devops探索

一、ftp服务器搭建

系统环境:

阿里云ECS主机

1 2

cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)

1、安装采用yum安装

1

yum -y install vsftpd ftp

2、服务目录

1 2 3 4 5 6 7 8 9 10 11

tree /etc/vsftpd/ /etc/vsftpd/ ├── ftpusers ├── user_list ├── vconf #新增目录 │   └── chenfei ├── vsftpd.conf ├── vsftpd.conf.bak #先做备份 ├── vsftpd_conf_migrate.sh ├── vusers #用户文件 └── vusers.db

3、将ftp添加到系统服务并开机启动

1

systemctl enable vsftpd

4、修改配置文件

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

anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 anon_mkdir_write_enable=YES dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES chown_uploads=YES xferlog_std_format=YES async_abor_enable=YES ascii_upload_enable=YES ascii_download_enable=YES ftpd_banner=Welcome to blah FTP service. chroot_local_user=YES listen=NO pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES use_localtime=YES listen_port=21 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=40000 pasv_max_port=40010 accept_timeout=5 connect_timeout=1 allow_writeable_chroot=YES

5、建立用户文件

1 2 3 4

cat /etc/vsftpd/vusers 用户名 密码

用户名和密码要单独占一行,且顺序不能变

6、生成用户数据文件

1

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

7、修改/etc/pam.d/vsftpd文件

1 2 3 4 5 6 7 8 9 10 11

cat /etc/pam.d/vsftpd #%PAM-1.0 session optional pam_keyinit.so force revoke #auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed #auth required pam_shells.so #auth include password-auth #account include password-auth session required pam_loginuid.so session include password-auth auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vusers account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vusers

注意将原来的auth和account项注释掉

8、创建系统用户vsftpd,用户的家目录为/home/vsftpd

1

useradd vsftpd -d /home/vsftpd -s /bin/false

用户登陆终端设置为/bin/false,目的是防止ssh登陆系统

9、建立虚拟用户的配置文件

1 2 3 4 5 6 7 8 9 10 11

mkdir /etc/vsftpd/vconf cd /etc/vsftpd/vconf cat test local_root=/home/vsftpd/test write_enable=YES anon_world_readable_only=NO anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES 建立test用户根目录 mkdir -p /home/vsftpd/test

10、防火墙设置

1 2

-A INPUT -s 本机IP/32 -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT -A INPUT -s 本机IP/32 -p tcp -m state --state NEW -m tcp --dport 40000:40010 -j ACCEPT

11、重启vsftpd服务

1

systemctl restart vsftpd

遇到的坑:

访问测试报错:

1、500 OOPS: unrecognised variable in config file: xxxx

这种一般是配置文件有错误,我这里出现错误的原因便是虚拟用户的个人配置文件有一项写错了。

2、200 Switching to ASCII mode 227 Entering Passive Mode

解决办法:

打开 “网络和共享中心”,找到“Internet选项” –>【高级】这页,取消掉“使用被动FTP(用于防火墙和DSL调制解调器的兼容)”

3、开启匿名用户访问时,不能创建目录和修改目录

解决办法:

1 2 3 4 5

修改配置文件: anonymous_enable=YES #允许匿名用户登陆 anon_upload_enable=YES #允许匿名用户上传 anon_other_write_enable=YES 重启服务

二、ftp命令介绍

1 2 3 4 5 6 7 8 9 10 11 12 13

ls 列出远程机的当前目录 cd 在远程机上改变工作目录 lcd 在本地机上改变工作目录 ascii 设置文件传输方式为ASCII模式 binary 设置文件传输方式为二进制模式 close 终止当前的ftp会话 hash 每次传输完数据缓冲区中的数据后就显示一个#号 get(mget) 从远程机传送指定文件到本地机 put(mput) 从本地机传送指定文件到远程机 open 连接远程ftp站点 断开与远程机的连接并退出ftp ? 显示本地帮助信息 ! 转到Shell中

ftp使用过程中遇到的问题

1、ftp:500 Illegal PORT command. ftp: bind: Address already in use

解决办法:

由于iptables不支持,需要加载两个模块:

1 2

modprobe ip_nat_ftp modprobe ip_conntrack_ftp

在客户端使用命令行或者软件连接时,ftp服务器的配置文件中需要保证有这几行配置:

1 2 3 4

pasv_enable=YES pasv_min_port=40000 pasv_max_port=40010 pasv_promiscuous=YES #如果不设置这个,会出现425 Security: Bad IP connecting.类似于这种的错误

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-05-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、ftp服务器搭建
  • 二、ftp命令介绍
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档