Linux 8开启FTP功能服务
不是很懂,简单写一下过程。本地账户测试的。
1、安装服务器
yum install vsftpd
2、编辑配置文件
vim /etc/vsftpd/ftpusers #用户文件 我这些都没改 vim /etc/vsftpd/user_list #用户文件 我这些都没改 vim /etc/vsftpd/vsftpd.conf #配置文件 这个改了,请看以下
# ASCII mangling is a horrible feature of the protocol. ascii_upload_enable=YES ascii_download_enable=YES # the presence of the "-R" option, so there is a strong case for enabling it. ls_recurse_enable=YES # with the listen_ipv6 directive. listen=NO #注意这个不能开启,会有错误,启动不了。 # Make sure, that one of the listen options is commented !! listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES
遇到的错误如下:
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2021-02-15 13:19:43 CST; 19s ago
Process: 10312 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=2)
Main PID: 9813 (code=killed, signal=TERM)
2月 15 13:19:43 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
2月 15 13:19:43 localhost.localdomain systemd[1]: vsftpd.service: Control process exited, code=exited status=2
2月 15 13:19:43 localhost.localdomain vsftpd[10312]: 500 OOPS: run two copies of vsftpd for IPv4 and IPv6
2月 15 13:19:43 localhost.localdomain systemd[1]: vsftpd.service: Failed with result 'exit-code'.
2月 15 13:19:43 localhost.localdomain systemd[1]: Failed to start Vsftpd ftp daemon.
3、关闭防火墙
#开放两个端口: firewall-cmd --zone=public --add-port=21/tcp --permanent firewall-cmd --zone=public --add-port=22/tcp --permanent #或者关闭防火墙 systemctl stop firewalld
#针对于CenOS8 Redhat8
#优化防火墙设置
暂时开启FTP服务
firewall-cmd --add-service=ftp
永久开放FTP服务
firewall-cmd --add-service=ftp --permanent
永久关闭FTP服务
firewall-cmd --remove-service=ftp --permanent
重启防火墙使设置生效
systemctl restart firewalld
5、开启目录
setsebool -P tftp_home_dir on sestatus -b | grep ftp
getsebool -a|grep ftp
setsebool -P allow_ftpd_full_access on
#setsebool -P tftp_home_dir on
4、启动服务
systemctl restart vsftpd.service
systemctl status vsftpd.service
#成功提示如下:
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-02-15 13:24:08 CST; 3s ago
Process: 10465 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 10466 (vsftpd)
Tasks: 1 (limit: 22983)
Memory: 544.0K
CGroup: /system.slice/vsftpd.service
└─10466 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
5、本机测试
#安装客户端 yum install ftp #测试服务 ftp xxx.xxx.xxx.xxx
6、问题,
530 Login incorrect.
需检查用户shell是否正确,可用终端登录一下用户。
cat /etc/passwd 和 cat /etc/shells 中是否有该shell存在。
500 OOPS: vsftpd: refusing to run with writable root inside chroot() Login f
vsftpd增强了安全,根目录下不能有写的权限,两种解决方式,
一种 chmod a-w 目录,
另一种在config中添加一条,allow_writeable_chroot=YES 屏蔽此安全。
关于两种用户设置:
- chroot_local_user #是否将所有用户限制在主目录,YES为启用 NO禁用.(该项默认值是NO,即在安装vsftpd后不做配置的话,ftp用户是可以向上切换到要目录之外的)
- chroot_list_enable #是否启动限制用户的名单 YES为启用 NO禁用(包括注释掉也为禁用)
- chroot_list_file=/etc/vsftpd/chroot_list #是否限制在主目录下的用户名单,至于是限制名单还是排除名单,这取决于chroot_local_user的值,我们可以这样记忆: chroot_local_user总是一个全局性的设定,其为YES时,全部用户被锁定于主目录,其为NO时,全部用户不被锁定于主目录。那么我们势必需要在全局设定下能做出一些“微调”,即,我们总是需要一种“例外机制",所以当chroot_list_enable=YES时,表示我们“需要例外”。而”例外“的含义总是有一个上下文的,即,当”全部用户被锁定于主目录“时(即chroot_local_user=YES),"例外"就是:不被锁定的用户是哪些;当"全部用户不被锁定于主目录"时(即chroot_local_user=NO),"例外"“就是:要被锁定的用户是哪些。这样解释和记忆两者之间的关系就很清晰了!
# 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. 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 David.DU 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 allow_writeable_chroot=YES # (default follows) chroot_list_file=/etc/vsftpd/chroot_list # # 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 listen_port=21 max_clients=100 max_per_ip=10 # # 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=NO userlist_deny=NO userlist_file=/etc/vsftpd/user_list pasv_enable=YES #pasv_promiscuous=NO pasv_min_port=30000 pasv_max_port=30999 #pasv_address=192.168.80.141 #pasv_addr_resolve=YES