使用vsftpd 搭建ftp 服务器

1. 简介:

使用vsftpd 在ubuntu环境中搭建ftp服务器。。Vsftp 是一个专门为unix类型系统设计一个ftp服务器,如linux。
Vsftpd 支持ipv6和ssl。支持explicit 和implicit FTPS(不是SFTP)。
vsftp是Ubuntu, CentOS, Fedora, NimbleX, Slackware,RHEL Linux 系统的默认ftp服务器.php

2. 配置环境

ubuntu16.04.1 x86_64 GNU/Linux
测试工具:FileZilla 3.36.0
**linux

3. 配置方法:

**
3.1. 安装vsftpd
sudo apt-get install vsftpd
vsftp安装好后会自动生成ftp user和ftp groupubuntu

3.2. 备份配置文件
vsftpd的配置文件位于/etc/vsftpd.conf
修改以前按需求备份一个原文件。
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.original服务器

3.3. 部分配置文件内容介绍ssh

3.3.1. 匿名用户登录ide

是否容许匿名用户登录ftp,默认YES,只容许Anonymous用户下载工具

# Allow anonymous FTP? (Disabled by default).                                                                                                
anonymous_enable=NO

3.3.2. 本地用户登录测试

为了容许在/etc/passwd内部用户登录ftp,需将此项设置为YESui

# Uncomment this to allow local users to log in.
local_enable=YES

3.3.3. 上传设置this

若需对系统进行读写操做,需将此项设置为YES
# Uncomment this to enable any form of FTP write command.

write_enable=YES

3.3.4. Chroot jail

#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

这是个颇有趣的变量,这个就是为了配置是否运行ftp用户离开其默认目录。设置以前,需手动添加vsftpd.chroot_list文件,此文件内存储ftp用户,其表明的含义根据chroot_local_user和chroot_list_enable不一样而不一样。
clipboard.png

此处将两项均设置为YES,并将但愿有全部目录访问权限的ftp用户存于vsftpd.chroot_list文件中。

3.3.5. 阻止用户登录

能够经过设置阻止部分用户访问ftp服务器。配置以下:

userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO

手动添加此三项到配置文件,同时建立vsftpd.user_list。与chroot jail配置参数类似,不一样的设置致使不一样的效果

clipboard.png

3.3.6. pam_service_name

pam_service_name参数用户配置虚拟ftp用户,需将此项设置为ftp,不然可能会出现530 Login incorrect登录失败错误。

# This string is the name of the PAM service vsftpd will use.
#pam_service_name=vsftpd
pam_service_name=ftp

3.3.7. 链接数量限制

将下列配置信息添加到vsftpd文件内

local_max_rate=1000000 # Maximum data transfer rate in bytes per second
max_clients=50         # Maximum number of clients that may be connected
max_per_ip=2           # Maximum connections per IP

3.3.8. 其余设置

显示隐藏文件

# Show hidden files and the "." and ".." folders.
# Useful to not write over hidden files:
force_dot_files=YES

隐藏文件全部者信息

# Hide the info about the owner (user and group) of the files.
hide_ids=YES

3.4. 重启vsftpd服务

经过重启vsftpd应用配置修改,重启服务有如下三种方式

1) sudo service vsftpd restart
2) sudo systemctl restart vsftpd.service
3) sudo /etc/init.d/vsftpd restart

3.5. FTP用户建立

useradd myusername

会在/home/路径下建立一个与用户名相同的文件夹,做为用户默认路径。可以使用useradd –d [directory] myusername选项在建立时指定默认路径,也可以使用usermod –d [directory] myusername 从新指定用户默认路径。

在建立用户时,可使用命令sudo usermod –s /usr/sbin/nologin myusername 来禁止ssh登录ftp用户

建立完成后,便可使用ftp工具进行链接。

4. 部分ERROR解决方法

4.1. 500 OOPS: vsftpd: refusing to run with writable root inside chroot ()

若将新建ftp用户路径指定到root路径下,如/var/www/ftp,在链接时可能会报500 OOPS: vsftpd: refusing to run with writable root inside chroot () 错误。解决方法有两种:
一、 使用 sudo chmod –R a-w [directory] 去除可写权限,采用此方法会失去上传功能
二、 在vsftpd.conf配置文件中添加allow_writeable_chroot=YES

4.2. 550 Access is denied

在进行上传操做时可能会遇到550访问被拒绝错误,此时须要查看上传路径是否给ftp用户提供了写入权限。

可能涉及到的命令:
1) 将myusername 用户加入另外一个用户组

usermod –a –G theothergroupname myusername

2) 将全部文件夹权限设置为755(drwxr-xr-x)

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

3) 将全部文件权限设置为644(-rw-r--r--)

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

**

5. 参考资料

**
[1]. Howto: Easy FTP with vsftpd, https://ubuntuforums.org/show...
[2]. Very Secure FTP Daemon , https://wiki.archlinux.org/in...
[3]. vsftpd 配置:chroot_local_user与chroot_list_enable详解, https://blog.csdn.net/bluishg...
[4]. How do I set chmod for a folder and all of its subfolders and files?, https://stackoverflow.com/que...

相关文章
相关标签/搜索