阿里云Ubuntu安装vsftpd提供ftp服务,出现很多问题,记录一下。

1、安装vsftpd

apt-get install vsftpd

2、创建ftp用户

#创建用户目录
mkdir /home/ftpdir
#创建用户
useradd -d /home/ftpdir -s /bin/bash ftpuser
#修改用户密码
passwd ftpuser
#加入文件夹权限,不然会提示open for write: permission denied错误
chmod 777 /home/ftpdir

3、配置vsftpd.conf

vi /etc/vsftpd.conf

编辑如下:

# Example config file /etc/vsftpd.conf

listen=YES
userlist_deny=NO
userlist_enable=YES
#允许登录的用户
userlist_file=/etc/allowed_users
seccomp_sandbox=NO
#默认ftp下载目录
local_root=/home/bookmarkftp/
local_enable=YES
#设置文件上传
write_enable=YES
#使用utf8
utf8_filesystem=YES

listen_ipv6=NO
#这里是你服务器的IPv4地址
pasv_address=xxx.xxx.xxx.xxx 
pasv_enable=YES
pasv_min_port=9000
pasv_max_port=9099
#
# Allow anonymous FTP? (Disabled by default).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES

dirmessage_enable=YES
#

use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=NO
#add 21 but no used.
ftp_data_port=21
#
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
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO

4、添加允许登录的用户,把ftpuser写入文件

vi /etc/allowed_users

5、启动、停止及重启服务

/etc/init.d/vsftpd start 
#或者 service vsftpd start   
 
/etc/init.d/vsftpd stop 
#或者 service vsftpd stop
 
/etc/init.d/vsftpd restart 
#或者service vsftpd restart

自此便可以通过22端口访问了,21端口目前一直不能访问,暂未解决(待更新)

卸载方法

apt-get purge vsftpd