ftp环境配置解决方案(vsftpd)

2019-02-1716:59:16服务器及运维Comments2,114 views字数 1395阅读模式

1、 安装vsftpd组件文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

安装命令:[root@ink4t ~]# sudo apt-get install vsftpd文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

2、 添加一个ftp用户文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

此用户就是用来登录ftp服务器用的。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

[root@ink4t ~]# useradd ftpuser

这样一个用户建完,可以用这个登录,记得用普通登录不要用匿名了。登录后默认的路径为 /home/ftpuser文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

3、 给ftp用户添加密码
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

[root@ink4t ~]# passwd ftpuser

输入两次密码后修改密码。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

4、 防火墙开启21端口文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

因为ftp默认的端口为21,而centos默认是没有开启的,所以要修改iptables文件文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

[root@ink4t ~]# vi /etc/sysconfig/iptables

在行上面有22 -j ACCEPT 下面另起一行输入跟那行差不多的,只是把22换成21,然后:wq保存。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

还要运行下,重启iptables文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

[root@ink4t ~]# service iptables restart

5、 修改配置文件vsftpd.conf文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

允许匿名用户访问,并且对匿名用户的目录进行限制,限制到/home/ftpuser文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

anonymous_enable=YES 
anon_root=/home/ftpuser

这里特别说明,/home/ftp目录,不能有w权限,这是一个只读的目录,否者会报错。修改权限可以使用文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

sudo chmod a-w /home/ftpuser

本地用户能够访问,且拥有写的权限文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

local_enable=YES 
write_enable=YES

本地用户登录后限制在自己的主目录下,同时通过文件/etc/vsftpd.chroot_list来指定不用限制目录的用户(比如我们的user1不用限制目录,所以要在该文件下写上user1),同时允许用户对自己的主目录进行修改。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

chroot_local_user=YES 
chroot_list_enable=YES 
chroot_list_file=/etc/vsftpd.chroot_list 
allow_writeable_chroot=YES

启用用户列表,不在列表中的用户禁止登陆(所以我们要在etc/allowed_users中写上user1,user2,anonymous,ftp,其中最后两个都表示匿名登录)文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

user_list_enable=YES 
user_list_deny=NO 
userlist_file=/etc/allowed_users

这个是经验项,配置了据说可以避免一些错误,参考文献中有介绍。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

seccomp_sandbox=NO

到此,还注意到,里面涉及到了两个文件,一个是/etc/vsftpd.chroot_list,一个是/etc/allowed_users,我们保存了之后需要自己手动创建这两个文件,文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

sudo touch /etc/vsftpd.chroot_list 
sudo touch /etc/allowed_users

然后在/etc/vsftpd.chroot_list中的用户不被限制目录,这个例子中我们要写入user1,/etc/allowed_users中要写入允许访问服务器的用户,这里就是user1,user2,还有匿名用户anonymous,ftpuser,注意写的时候每行只写一个用户名。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/9615.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/9615.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定