CentOS中vsftp服务安装、配置、卸载
1.检查centos是否安装vsftpd
[root@localhost zhangzhuo]# rpm -aq vsftpd
vsftpd-3.0.2-22.el7.x86_64 #查询的返回结果,表明已安装
若要卸载Vfstpd:
[root@localhost zhangzhuo]# rpm -e vsftpd-3.0.22-22.el7.x86_64
由于我的vsftpd服务已搭建好,所以就不给演示删除,但我之前配置错误,用此方法删除是没有问题的
查看是否卸载了vsftpd:
[root@localhost zhangzhuo]# /sbin/service vsftpd stop
[root@localhost zhangzhuo]# /sbin/service vsftpd start
#在卸载vsftpd之前要 先停止vsftpd
2.安装vsftpd
[root@localhost zhangzhuo]# yum -y install vsftpd
3.修改vsftpd.conf文件
[root@localhost zhangzhuo]# vi /etc/vsftpd/vsftpd.conf
1 # Example config file /etc/vsftpd/vsftpd.conf 2 # 3 # The default compiled in settings are fairly paranoid. This sample file 4 # loosens things up a bit, to make the ftp daemon more usable. 5 # Please see vsftpd.conf.5 for all compiled in defaults. 6 # 7 # READ THIS: This example file is NOT an exhaustive list of vsftpd options. 8 # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's 9 # capabilities. 10 # 11 # Allow anonymous FTP? (Beware - allowed by default if you comment this out). 12 #anonymous_enable=YES 13 # 14 # Uncomment this to allow local users to log in. 15 # When SELinux is enforcing check for SE bool ftp_home_dir 16 local_enable=YES 17 # 18 # Uncomment this to enable any form of FTP write command. 19 write_enable=YES 20 # 21 # Default umask for local users is 077. You may wish to change this to 022, 22 # if your users expect that (022 is used by most other ftpd's) 23 local_umask=022 24 # 25 # Uncomment this to allow the anonymous FTP user to upload files. This only 26 # has an effect if the above global write enable is activated. Also, you will 27 # obviously need to create a directory writable by the FTP user. 28 # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access 29 #anon_upload_enable=YES 30 # 31 # Uncomment this if you want the anonymous FTP user to be able to create 32 # new directories. 33 #anon_mkdir_write_enable=YES 34 # 35 # Activate directory messages - messages given to remote users when they 36 # go into a certain directory. 37 dirmessage_enable=YES 38 # 39 # Activate logging of uploads/downloads. 40 xferlog_enable=YES 41 # 42 # Make sure PORT transfer connections originate from port 20 (ftp-data). 43 connect_from_port_20=YES 44 # 45 # If you want, you can arrange for uploaded anonymous files to be owned by 46 # a different user. Note! Using "root" for uploaded files is not 47 # recommended! 48 #chown_uploads=YES 49 #chown_username=whoever 50 # 51 # You may override where the log file goes if you like. The default is shown 52 # below. 53 #xferlog_file=/var/log/xferlog 54 # 55 # If you want, you can have your log file in standard ftpd xferlog format. 56 # Note that the default log file location is /var/log/xferlog in this case. 57 xferlog_std_format=YES 58 # 59 # You may change the default value for timing out an idle session. 60 idle_session_timeout=600 61 # 62 # You may change the default value for timing out a data connection. 63 data_connection_timeout=120 64 # 65 # It is recommended that you define on your system a unique user which the 66 # ftp server can use as a totally isolated and unprivileged user. 67 #nopriv_user=ftpsecure 68 # 69 # Enable this and the server will recognise asynchronous ABOR requests. Not 70 # recommended for security (the code is non-trivial). Not enabling it, 71 # however, may confuse older FTP clients. 72 #async_abor_enable=YES 73 # 74 # By default the server will pretend to allow ASCII mode but in fact ignore 75 # the request. Turn on the below options to have the server actually do ASCII 76 # mangling on files when in ASCII mode. 77 # Beware that on some FTP servers, ASCII support allows a denial of service 78 # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd 79 # predicted this attack and has always been safe, reporting the size of the 80 # raw file. 81 # ASCII mangling is a horrible feature of the protocol. 82 ascii_upload_enable=YES 83 ascii_download_enable=YES 84 # 85 # You may fully customise the login banner string: 86 ftpd_banner=Welcome to blah FTP service. 87 # 88 # You may specify a file of disallowed anonymous e-mail addresses. Apparently 89 # useful for combatting certain DoS attacks. 90 #deny_email_enable=YES 91 # (default follows) 92 #banned_email_file=/etc/vsftpd/banned_emails 93 # 94 # You may specify an explicit list of local users to chroot() to their home 95 # directory. If chroot_local_user is YES, then this list becomes a list of 96 # users to NOT chroot(). 97 # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that 98 # the user does not have write access to the top level directory within the 99 # chroot) 100 chroot_local_user=YES 101 #chroot_list_enable=YES 102 # (default follows) 103 #chroot_list_file=/etc/vsftpd/chroot_list 104 # 105 # You may activate the "-R" option to the builtin ls. This is disabled by 106 # default to avoid remote users being able to cause excessive I/O on large 107 # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume 108 # the presence of the "-R" option, so there is a strong case for enabling it. 109 ls_recurse_enable=YES 110 # 111 # When "listen" directive is enabled, vsftpd runs in standalone mode and 112 # listens on IPv4 sockets. This directive cannot be used in conjunction 113 # with the listen_ipv6 directive. 114 listen=YES 115 # 116 # This directive enables listening on IPv6 sockets. By default, listening 117 # on the IPv6 "any" address (::) will accept connections from both IPv6 118 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6 119 # sockets. If you want that (perhaps because you want to listen on specific 120 # addresses) then you must run two copies of vsftpd with two configuration 121 122 # files. 123 # Make sure, that one of the listen options is commented !! 124 #listen_ipv6=YES 125 126 pam_service_name=vsftpd 127 userlist_enable=YES 128 userlist_deny=NO 129 local_root=/var/public_root 130 tcp_wrappers=YES 131 use_localtime=YES 132 allow_writeable_chroot=YES
最后一句,为了解决“当我们限定了用户不能跳出其主目录之后,使用该用户登录FTP时遇到的错误”:
1 500 OOPS: vsftpd: refusing to run with writable root inside chroot ()
这个问题发生在最新的这是由于下面的更新造成的:
1 Add stronger checks for the configuration error of running with a writeable root directory inside a chroot()
从2.3.5之后,vsftpd增强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了!如果检查发现还有写权限,就会报该错误。
要修复这个错误,可以用命令chmod a-w /home/user去除用户主目录的写权限,注意把目录替换成你自己的。或者你可以在vsftpd的配置文件中增加标红的最后一句话
3.添加ftp账户
为了方便记忆,这里设置的账户为vsftpd、密码为123456
1 [root@localhost zhangzhuo]# useradd vsftpd -s /sbin/nologin 2 [root@localhost zhangzhuo]# passwd vsftpd
4.编辑user_list文件,允许vsftpd访问ftp
1 [root@localhost zhangzhuo]# vi /etc/vsftpd/user_list
1 # vsftpd userlist 2 # If userlist_deny=NO, only allow users in this file 3 # If userlist_deny=YES (default), never allow users in this file, and 4 # do not even prompt for a password. 5 # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers 6 # for users that are denied. 7 root 8 bin 9 daemon 10 adm 11 lp 12 sync 13 shutdown 14 halt 15 mail 16 news 17 uucp 18 operator 19 games 20 nobody 21 vsftpd 22 ~ 23 ~ 24 ~
5.建立根目录,设置访问权限
1 [root@localhost zhangzhuo]# mkdir /var/public_root 2 [root@localhost zhangzhuo]# chown -R vsftpd /var/public_root 3 [root@localhost zhangzhuo]# chmod -R 755 /var/public_root
6.关闭防火墙或开放21端口
ftp设置好了之后,服务启动了但连接失败,ftp默认是21号端口,但Linux的21端口默认是关闭的,关闭防火可以解决,但不推荐
1 firewall-cmd –state ----> 查看防火墙状态 2 service firewalld start ----> 启动防火墙 3 service firewalld restart ----> 重启防火墙 4 service firewalld stop -----> 关闭防火墙 5 firewall-cmd --query-port=21/tcp ----->查询端口是否开放 6 firewall-cmd --permanent --add-port=21/tcp ----->开放21端口 7 firewall-cmd --permanent --remove-port=21/tcp ----->移除端口 8 firewall-cmd --reload ----->重启防火墙(修改配置后要重启防火墙)
7.开启vsftpd服务
1 [root@localhost zhangzhuo]# service vsftpd start 2 [root@localhost zhangzhuo]# systemctl status vsftpd.service #查看vsftpd服务状态 3 [root@localhost zhangzhuo]# systemctl restart vsftpd.service #重启vsftpd服务
8.设置开机启动vsftpd服务
1 [root@localhost zhangzhuo]# chkconfig vsftpd on
至此,ftp服务就搭建起来了,可以通过物理主机的dos命令行使用"ftp linux虚拟机IP"或者FileZilla软件进行连接测试
博主也是菜鸟一只,若给您带来帮助,不胜荣幸;若有什么问题,欢迎踩我,大家共同学习进步,提高技术,谢谢!