Ubuntu下ftp server 搭建

FTP服务器是在互联网上提供文件存储和访问服务的计算机,它们依照FTP协议提供服务
先安装vsftpd,再进行配置,其配置文件在/etc/vsftpd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
listen=YES  //是否以守护进程独立运行
// Allow anonymous FTP? (Disabled by default)
anonymous_enable=NO //是否允许匿名登录
// allow local users to log in.
local_enable=YES //运行本地用户登录
// enable any form of FTP write command.
write_enable=YES //用户对ftp服务器文件是否有写权限
local_umask=022 //文件上传后的权限为该值取反
dirmessage_enable=YES //激活目录信息,当远程用户更改目录时,将出现提示信息
use_localtime=YES //是否用本地时间
// Activate logging of uploads/downloads.
xferlog_enable=YES //启用上传和下载日志功能
connect_from_port_20=YES //启用FTP数据端口的连接请求
xferlog_file=/var/log/vsftpd.log //设置日志文件
//控制登录FTP的用户是否被限制在家目录下
//若参数为YES,chroot_list_file中的用户都被限制在自己的home目录
//即文件中的用户都只能访问自己的家目录,其他用户都不被限制在自己的home目录
//否则相反,即list名单为特例名单
chroot_local_user=YES
//是否启用list名单
chroot_list_enable=YES
// (default follows)
//文件中写需要被限制的用户名
chroot_list_file=/etc/vsftpd.chroot_list //设置list文件路径
//chroot用户是否有写权限
allow_writeable_chroot=YES
secure_chroot_dir=/var/run/vsftpd/empty
// This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
// This option specifies the location of the RSA certificate to use
// for SSL encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
// This option specifies the location of the RSA key to use for SSL
// encrypted connections.
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
//是否开启list文件
userlist_enable=yes
//no:list文件中用户可登录
//yes:list文件中用户不可登录
userlist_deny=no
//设置list文件路径,list文件中写用户名
userlist_file=/etc/vsftpd.user_list
seccomp_sandbox=NO
//check_shell=NO

ubuntu下配置完后出现错误
500 OOPS: prctl PR_SET_SECCOMP failed
解决:seccomp_sandbox=NO
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
如果开启了chroot来控制用户路径,则用户不能再具有该用户家目录的写的权限
解决方法1:将该用户家目录的写权限(chmod a-w)
但是这样用户不再具有写权限,自然也上传不了文件
解决方法2:allow_writeable_chroot=YES
设置用户只能进行ftp文件传输,不能登录shell
useradd -d /home/ftp -m -s /usr/sbin/nologin ftp
-d设置家目录 -m若设置的家目录不存在会创建目录 -s用户的登录shell
结果登录不上ftp服务器,解决方法:在/etc/shells文件中添加/usr/sbin/nologin