centos7.4 开启ftp服务
2024-08-26 10:38:16
1、安装vsftpd
yum install -y ftp vsftpd
2、配置/etc/vsftpd/vsftpd.conf
修改项如下:
#不允许匿名访问
anonymous_enable=NO #限制用户通过ftp只能访问自己的主目录
chroot_local_user=YES
#是否开启限制名单
chroot_list_enable=YES
#限制名单的路径
chroot_list_file=/etc/vsftpd/chroot_list
3、编辑/etc/vsftpd/chroot_list
内容如下
ftpuser
这里是先将ftpuser这个用户限制在自己的主目录中,ftpuser这个用户需要我们手动创建
4、创建用户
#创建用户ftpuser,设置其主目录为/home/ftpuser
useradd -d /home/ftpuser ftpuser #限定用户ftpuser不能telnet
usermod -s /sbin/nologin ftpuser #如果想将用户恢复正常命令如下
usermod -s /sbin/bash ftpuser #更改用户ftpuser的主目录为/usr/share/nginx/html
usermod -d /usr/share/nginx/html ftpuser
#设置用户密码
passwd ftpuser
#如果将用户的主目录设置到某个已有的目录下,一定要保证该目录可被该用户访问
#可以参考chmod命令相关内容chmod 666 [目录路径]
5、调整selinux
selinux的存在可能会导致用户打开文件夹看到的文件列表为空或者无法进入文件夹,selinux操作方式如下:
setsebool -P ftpd_disable_trans 1 或者 setsebool -P ftp_home_dir on
然后重启FTP服务
以下说明摘自 传送门
# setsebool -P allow_ftpd_anon_write= #允许ftpd匿名用户可写
# setsebool -P ftp_home_dir #允许用户访问自己的根目录
# setsebool -P ftpd_is_daemon #允许daemon运行ftpd
# setsebool -P ftpd_disable_trans #关闭SELINUX对ftpd的保护
# setsebool -P allow_httpd_anon_write= #允许httpd匿名用户可写
# setsebool -P allow_httpd_sys__anon_write= #同上
# setsebool -P httpd_enable_cgi #httpd被设置允许cgi被执行
# setsebool -P httpd_enable_homedirs #允许访问用户的根目录
# setsebool -P httpd_tty_comm #允许httpd控制终端
# setsebool -P httpd_unified #httpd之间相互独立
# setsebool -P httpd_builtin_ing #同httpd环境一样运行
# setsebool -P httpd_can_network_connect #httpd可以连接到网络
# setsebool -P httpd_suexec_disable_trans #禁用suexec过度
# setsebool -P httpd_disable_trans #允许daemon用户启动httpd
# setsebool -P named_write_master_zones #允许修改dns的主zone文件
# setsebool -P named_disable_trans #允许daemon启动named
# setsebool -P nfs_export_all_ro #nfs只读
# setsebool -P nfs_export_all_rw #nfs可读写
# setsebool -P use_nfs_home_dirs #允许本机访问远程nfs的根目录
# setsebool -P allow_smbd_anon_write= #samba允许匿名用户可写
# setsebool -P samba_enable_home_dirs #允许根目录访问
# setsebool -P use_samba_home_dirs #允许本机访问远程samba根目录
# setsebool -P smbd_disable_trans #允许daemon启动samba
# setsebool -P allow_rsync_anon_write= #允许匿名用户可写
# setsebool -P rsync_disable_trans #允许daemon启动rsync
也可以永久关闭selinux:
vim /etc/selinux/config 改SELINUX=disabled # 保存退出,重启服务器 reboot
6、防火墙操作
可以直接关闭防火墙:
systemctl stop firewalld
systemctl disable firewalld
如果要保持防火墙常开请注意以下端口的打开
20、21端口,此外还要
1:修改配置文件
vi /etc/vsftpd/vsftpd.conf
2:在末尾添加
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
然后重启vsftpd服务
上文配置的 30000到31000是Vsftpd被动模式需要的端口,也需要在防火墙中打开
部分其它配置说明:
https://blog.csdn.net/bluishglc/article/details/42398811
https://blog.csdn.net/bluishglc/article/details/42273197
最新文章
- 用php做注册审核
- 【原创】开源Math.NET基础数学类库使用(01)综合介绍
- Web项目的发布新手教程
- 解决nf_conntrack: table full, dropping packet问题
- 剑指offer题目21-30
- UINavigationItem和UItabBarItem的区别详解
- Python模块(radom)
- Linux Mysql 1130错误解决
- Core Java Volume I — 4.5. Method Parameters
- cf701B Cells Not Under Attack
- poj 2446 (二分匹配)
- HDU 4085 Steiner树模板称号
- Paper藐小之处明察秋毫故时有物外之趣
- 2017OKR年终回顾与2018OKR初步规划
- java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.SpecialProvider.<;init>;()
- springboot 如何操作redis
- Android 使用 HTTPS 问题解决(SSLHandshakeException)
- Confluence 6 权限设置
- System.Drawing.Drawing2D.LinearGradientBrush
- int 和Integer