在Ubuntu系统上搭建Ftp服务器(保姆级教程)

FTP(File Transfer Protocol)是一种文件传输协议,可以用于在计算机之间进行文件传输。安装FTP服务器可以让你轻松地在多台设备间进行文件传输,在工作很多场景中都会用到,那如何在Ubuntu系统上搭建Ftp服务器呢?

创建FTP用户

useradd -m -d /home/ftp ftp_user

安装vsftpd服务器

sudo apt-get update
sudo apt-get install vsftpd

配置vsftpd.conf文件

配置文件:sudo vi /etc/vsftpd.conf

# Allow anonymous FTP? (Disabled by default).
#是否允许匿名登录,一般不允许
anonymous_enable=NO

#是否允许本机用户登录
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
#允许上传文件到ftp服务器
write_enable=YES

# 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

userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd/user_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES

#utf8_filesystem=YES
#配置ftp服务器的上传下载文件所在的目录。
local_root=/home/ftp

配置用户

新建 /etc/vsftpd.chroot_list 文件,在里面添加登录ftp服务器的linux用户

sudo vi /etc/vsftpd.chroot_list

vsftpd.chroot_list文件内容,jack是我linux的用户名:

jack

配置ftp上传/下载文件的存放目录

这个目录要和vsftpd.conf中配置路径一致,比如上面配置的是local_root=/home/ftp,就新建/home/ftp目录

服务重启,配置生效

sudo /etc/init.d/vsftpd restart

本地登录验证

ftp服务配置完成后,可以现在本地登录验证ftp 127.0.0.1

登录验证

常见问题

1、禁止FTP用户登录ssh, 但是能正常登录FTP

#不允许ftp用户ssh登录
#打开/etc/shells,添加“/usr/bin/nologin”,即可
usermod -s /usr/bin/nologin username

#允许ftp用户ssh登录
usermod -s /bin/bash username

2、服务器修改ftp默认21端口

vim /etc/vsftpd.conf
# 尾部新增下面这一行
#listen_port=8021
# 重启服务
/etc/init.d/vsftpd restart

# 查看新监听的端口
netstat -utlpn | grep vsftp

3、限制用户只能访问主目录

$ vim /etc/vsftpd/chroot_list

# 这里可以填入用户,如 user1。
# 如果不填 user1,那么 user1 登录后直接访问到的目录是 /home/ftp,并且不能访问上一级
# 如果填了 user1,那么 user1 可以访问上一级
# 但不管填不填,都需要有这个文件

# 通过搭配能实现以下几种效果:
# ① 当chroot_list_enable=YES,chroot_local_user=YES时,在/etc/vsftpd.chroot_list文件中列出的用户,可以切换到其他目录;未在文件中列出的用户,不能切换到其他目录。
# ② 当chroot_list_enable=YES,chroot_local_user=NO时,在/etc/vsftpd.chroot_list文件中列出的用户,不能切换到其他目录;未在文件中列出的用户,可以切换到其他目录。
# ③ 当chroot_list_enable=NO,chroot_local_user=YES时,所有的用户均不能切换到其他目录。
# ④ 当chroot_list_enable=NO,chroot_local_user=NO时,所有的用户均可以切换到其他目录。
  1. FileZilla ftp传输:550 Permission denied
    1. 找到配置文件文件 vsftpd.conf :$ locate vsftpd.conf(一般在/etc/vsftpd.conf)
    2. 文件编辑:sudo vi vsftpd.conf
    3. 在vsftpd.conf中找到 #write_enable=YES:命令行模式下输入/write_enable,回车
    4. 重启vsftpd
如何搭建一个SSH代理服务?
Linux下清除屏幕的6个命令
标签:

发表我的评论

电子邮件地址不会被公开。 必填项已用*标注

26 + 31 =

ajax-loader