centos7上搭建ftp服务器
2021/12/22 7:19:56
本文主要是介绍centos7上搭建ftp服务器,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1. Centos7安装搭建FTP服务器(最简便方法) - Tse先生 - 博客园
2. Linux下搭建FTP服务器教程_LMXQH的博客-CSDN博客_linuxftp服务器配置
3. vsftpd 530 Login incorrect 根本原因和解决方案_wqh0830的博客-CSDN博客_530login incorrect
4. linux vsftpd 550 create directory operation failed解决方法 - 咣咣敲代码 - 博客园
主要参考以上博客
1. 安装ftp
yum -y install vsftpd
cd /etc/vsftpd
ls查看当前目录,应该是有以下内容:
然后复制user_list文件,将其改名为chroot_list,里面内容不用动
这个是为了避免这个错误
2. 修改vsftpd.conf文件
下面是我的配置文件,主要是把第一个改成NO,加了最后几行,没有ipv6的记得要把ipv6改成no,后续ftp连接的端口就是最后listen_port对应的数字
vim vsftpd.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 # # 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 # # 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 # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES # # 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 # (default follows) chroot_list_file=/etc/vsftpd/chroot_list allow_writeable_chroot=YES # # 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 listen_port=60021 pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES pasv_enable=YES pasv_min_port=65400 pasv_max_port=65410
3. 开防火墙,这里的port和范围是conf文件里写的范围
#添加主端口 [root@tsemongo01 vsftpd]# firewall-cmd --permanent --zone=public --add-port=60021/tcp success #添加被动端口 [root@tsemongo01 vsftpd]# firewall-cmd --permanent --zone=public --add-port=65400-65410/tcp success [root@tsemongo01 vsftpd]# firewall-cmd --reload success
4. 创建新用户ftpuser
useradd -d /home/ftpuser/ -s /sbin/nologin ftpuser
设置密码
passwd ftpuser
vim /etc/passwd
如果etc/passwd里面ftpuser对应的是bin/bash,修改为/sbin/nologin
(图里面home目录不用管,我自己创建的)
修改权限
chown -R ftpuser /home/ftpuser
5. 开启ftp服务
systemctl enable vsftpd
systemctl start vsftpd
netstat -antup | grep ftp
p.s. 注意 之后如果自己修改了conf文件之后要service vsftpd restart
6. 远程连接
windows端下载filezilla,记得下客户端版本,不是服务器版本
登录后,出现了错误
解决方法
查看/etc/ftpusers和user list,确认ftp用户不在这两个文件里面
修改/etc/pam.d/vsftpd,把pam_shells改成pam_nologin
#%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 required pam_nologin.so auth include password-auth account include password-auth session required pam_loginuid.so session include password-auth
开启文件夹修改权限
ftp设置了之后
没有办法修改里面的文件
这个通过修改SELinux解决,代表级别改为SELINUX=disabled 重启就OK了!
vim /etc/selinux/config
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
然后重启服务器,不想重启的也可以执行以下命令:
setenforce 0
然后就可以自由使用ftp了
这篇关于centos7上搭建ftp服务器的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14Fetch / Axios学习:入门教程与实战指南
- 2024-11-14Typescript 类型课程入门教程
- 2024-11-14Fetch / Axios课程:初学者必看的网络请求教程
- 2024-11-14Styled-components课程:初学者指南
- 2024-11-13pre-commit 自动化测试课程:入门教程与实践指南
- 2024-11-13什么是AIGC?如何使用AIGC技术辅助办公?
- 2024-11-13Slicm 框架怎么进行用户认证?-icode9专业技术文章分享
- 2024-11-13在查询时将 map_coord 列的值转换为字符串有哪些方法?-icode9专业技术文章分享
- 2024-11-13如何将微信地区改成自定义文案?-icode9专业技术文章分享
- 2024-11-13DNS 缓存存在问题有哪些症状和解决方法?-icode9专业技术文章分享