linux安装vsftp--centos8
ftp有两种工作模式,主动模式(port)和被动模式(passive)
主动模式:主动模式相对有利于服务端,在客户端访问服务端的21端口(默认端口不变的情况下)确认要进行ftp数据传输后,是客户端开放1024以上的随机端口给服务端去访问进行数据传输,对于客户端的网络管理是较不便的。
被动模式:被动模式相对有利于客户端,在客户端发送pasv信号通过21端口传送给服务端口,服务端会响应并开放vsftp.conf文件中配置的pasv_min_port和pasv_max_port范围内的随机端口,对于服务端防火墙等配置有要求。
一、准备工作
1、检查服务器有没有安装过vsftp,然后检查本地yum库里有没有安装包。
[root@docker ~]# rpm -qa | grep vsftpd [root@docker ~]# which vsftpd /usr/bin/which: no vsftpd in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) 上面说明服务器还没有安装ftp server,可以检查服务器有没有这个安装包了 [root@docker ~]# yum list | grep vsftpd vsftpd.x86_64 3.0.3-28.el8 AppStream
2、关闭selinux
二、开始安装
1、执行yum安装语句
yum -y isntall vsftpd
2、启动相关程序
[root@docker ~]# systemctl start vsftpd --启动ftp [root@docker ~]# systemctl enable vsftpd --将ftp加入到开机自启动 Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /usr/lib/systemd/system/vsftpd.service. [root@docker ~]# netstat -antup | grep ftp --检查ftp服务是否在监听 tcp6 0 0 :::21 :::* LISTEN 32333/vsftpd
三、vsftp的相关配置解析
[root@docker ~]# cd /etc/vsftpd/
[root@docker vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
1、ftpusers 即ftp黑名单用户,只要在这个文件内的用户,均无法使用ftp服务。
2、user_list 是和vsftpd.conf中的userlist_enable和userlist_deny两个配置项紧密相关的,它可以有效,也可以无效,有效时它可以是一个黑名单,也可以是一个白名单!
(1)userlist_enable和userlist_deny两个选项联合起来针对的是:本地全体用户(除去ftpusers中的用户)和出现在user_list文件中的用户以及不在在user_list文件中的用户这三类用户集合进行的设置。 (2)当且仅当userlist_enable=YES时:userlist_deny项的配置才有效,user_list文件才会被使用;当其为NO时,无论userlist_deny项为何值都是无效的,本地全体用户(除去ftpusers中的用户)都可以登入FTP (3)当userlist_enable=YES时,userlist_deny=YES时:user_list是一个黑名单,即:所有出现在名单中的用户都会被拒绝登入; (4)当userlist_enable=YES时,userlist_deny=NO时:user_list是一个白名单,即:只有出现在名单中的用户才会被准许登入(user_list之外的用户都被拒绝登入);另外需要特别提醒的是:使用白名单后,匿名用户将无法登入!除非显式在user_list中加入一行:anonymous
3、配置vsftp.conf
# Example config file /etc/vsftpd/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all compiled in defaults. # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's # capabilities. # # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=NO ---是否允许匿名登录 # # Uncomment this to allow local users to log in. # When SELinux is enforcing check for SE bool ftp_home_dir local_enable=YES ----是否允许本地用户登录FTP服务器 # # Uncomment this to enable any form of FTP write command. write_enable=YES ----是否对登录用户开启写权限。属全局性设置。 # # Default umask for local users is 077. You may wish to change this to 022, # if your users expect that (022 is used by most other ftpd's) local_umask=022 --目录和文件被创建时得到的初始权限,022即目录权限755,文件权限644 # # Uncomment this to allow the anonymous FTP user to upload files. This only # has an effect if the above global write enable is activated. Also, you will # obviously need to create a directory writable by the FTP user. # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access #anon_upload_enable=YES # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. #anon_mkdir_write_enable=YES # # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES --当用户进入某个目录时,会显示该目录需要注意的内容 # # Activate logging of uploads/downloads. xferlog_enable=YES --当设定为 YES 时,使用者上传与下载文件都会被纪录起来。 # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES --默认的数据传输端口为20 # # If you want, you can arrange for uploaded anonymous files to be owned by # a different user. Note! Using "root" for uploaded files is not # recommended! #chown_uploads=YES #chown_username=whoever # # You may override where the log file goes if you like. The default is shown # below. #xferlog_file=/var/log/xferlog # # If you want, you can have your log file in standard ftpd xferlog format. # Note that the default log file location is /var/log/xferlog in this case. xferlog_std_format=YES # # You may change the default value for timing out an idle session. #idle_session_timeout=600 # # You may change the default value for timing out a data connection. #data_connection_timeout=120 # # It is recommended that you define on your system a unique user which the # ftp server can use as a totally isolated and unprivileged user. #nopriv_user=ftpsecure # # Enable this and the server will recognise asynchronous ABOR requests. Not # recommended for security (the code is non-trivial). Not enabling it, # however, may confuse older FTP clients. #async_abor_enable=YES # # By default the server will pretend to allow ASCII mode but in fact ignore # the request. Turn on the below options to have the server actually do ASCII # mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains # the behaviour when these options are disabled. # Beware that on some FTP servers, ASCII support allows a denial of service # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd # predicted this attack and has always been safe, reporting the size of the # raw file. # ASCII mangling is a horrible feature of the protocol. #ascii_upload_enable=YES #ascii_download_enable=YES # # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. # # You may specify a file of disallowed anonymous e-mail addresses. Apparently # useful for combatting certain DoS attacks. #deny_email_enable=YES # (default follows) #banned_email_file=/etc/vsftpd/banned_emails # # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that # the user does not have write access to the top level directory within the # chroot) chroot_local_user=YES ---指定用户列表文件中的用户允许切换到上级目录 chroot_list_enable=YES --是否启用chroot_list_file配置指定的用户列表 # (default follows) chroot_list_file=/etc/vsftpd/chroot_list ---默认该文件不存在,需手动创建,主要是在 前两项均为YES时,配置可以cd到上级目录的用户。 # You may activate the "-R" option to the builtin ls. This is disabled by # default to avoid remote users being able to cause excessive I/O on large # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume # the presence of the "-R" option, so there is a strong case for enabling it. #ls_recurse_enable=YES # # 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. 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_ipv6=YES pam_service_name=vsftpd userlist_enable=YES
allow_writeable_chroot=YES --对vsftpd有用,否则因home目录权限而无法登录
pasv_enable=YES
pasv_min_port=50000
pasv_max_port=60000
listen_port=2121 --修改默认端口号
注意
编辑/etc/services文件
修改ftp配置,将21改成2121
重启vsftpd
[root@docker vsftpd]# systemctl restart vsftpd
测试端口是否已变更。
[root@docker vsftpd]# netstat -antup | grep vsftpd tcp6 0 0 :::2121 :::* LISTEN 33275/vsftpd
四、添加ftp用户
一般添加ftp服务,都是要存文件之类的,可以指定一个挂在了较大磁盘空间的目录做为ftp用户的家目录。
[root@docker ~]# useradd -d /data -s /sbin/nologin -g ftptest ahftp useradd: warning: the home directory already exists. Not copying any file from skel directory into it.
[root@docker ~]# cat /etc/passwd
ahftp:x:1001:1001::/data:/sbin/nologin
设置ftp用户nologin后,需要在shell内添加该项。
输入 cat /etc/pam.d/vsftpd | fgrep pam_shell 后显示为:
auth required pam_shells.so
看到以上结果后,再次输入 :echo "/sbin/nologin" >> /etc/shells
五、防火墙策略
[root@docker data]# firewall-cmd --permanent --add-port=2121/tcp success [root@docker data]# firewall-cmd --permanent --add-port=50000-60000/tcp success [root@docker data]# firewall-cmd --reload success [root@docker data]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: cockpit dhcpv6-client ssh ports: 10086/tcp 2121/tcp 50000-60000/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
六、测试
建议先本地测试。
原文地址:https://www.cnblogs.com/chxmtl/p/12973714.html
- linux下 Error running javac compiler
- 讨厌算法的程序员 1 - 插入排序
- Linux下使用ssh密钥实现无交互备份
- [编程经验] Python中的continue和break语句
- 洛谷 P3386 【模板】二分图匹配 Dinic版
- [编程经验] 拉勾网爬虫数据的后续处理
- Linux下使用rsync实现文件备份
- 【干货】基于TensorFlow卷积神经网络的短期股票预测
- [编程经验] 基于bs4的拉勾网AI相关工作爬虫实现
- [编程经验] 链家23个全国主要城市的现房数据分析
- [编程经验] Python中的modlue和packages的区别
- Day5上午解题报告
- [编程经验] Pandas中比较好用的几个方法
- [编程经验] Elasticsearch 初识
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android自定义View实现五子棋游戏
- AndroidQ(10)黑暗模式适配的实现
- Android仿微信录音功能
- android实现截图并动画消失效果的思路详解
- 位运算判断奇偶数
- Kotlin之在Gradle中无参(no-arg)编译器插件的使用详解
- android实现常驻通知栏遇到的问题及解决办法
- Android仿微信键盘切换效果
- Android实现WIFI和GPRS网络的切换
- 在VS2010里快要疯掉的hello world
- gh0st源码分析与远控的编写(三)
- Android自定义View实现五星好评效果
- Android通过ViewModel保存数据实现多页面的数据共享功能
- Android自定义View实现炫酷进度条
- OpenSSL的VC编程 - MD5