Ubantu搭建FTP

1.安装并启动 FTP 服务

安装 VSFTPD

使用 apt-get 安装 vsftpd

kylin@kylin:~$ sudo apt-get install vsftpd -y
[sudo] password for kylin: 
Sorry, try again.
[sudo] password for kylin: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gtk2-engines-xfce libkeybinder-3.0-0 libxfce4panel-2.0-4 libxfce4ui-utils
  linux-headers-4.10.0-28 linux-headers-4.10.0-28-generic
  linux-image-4.10.0-28-generic linux-image-extra-4.10.0-28-generic orage
  tango-icon-theme thunar thunar-volman xfce4-appfinder xfce4-panel
  xfce4-pulseaudio-plugin
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  vsftpd
0 upgraded, 1 newly installed, 0 to remove and 28 not upgraded.
Need to get 115 kB of archives.
After this operation, 336 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 vsftpd amd64 3.0.3-3ubuntu2 [115 kB]
Fetched 115 kB in 0s (1,212 kB/s)
Preconfiguring packages ...
Selecting previously unselected package vsftpd.
(Reading database ... 288442 files and directories currently installed.)
Preparing to unpack .../vsftpd_3.0.3-3ubuntu2_amd64.deb ...
Unpacking vsftpd (3.0.3-3ubuntu2) ...
Processing triggers for systemd (229-4ubuntu21) ...
Processing triggers for ureadahead (0.100.0-19) ...
ureadahead will be reprofiled on next reboot
Processing triggers for man-db (2.7.5-1) ...
Setting up vsftpd (3.0.3-3ubuntu2) ...
Processing triggers for systemd (229-4ubuntu21) ...
Processing triggers for ureadahead (0.100.0-19) ...

 

启动 VSFTPD
安装完成后 VSFTPD 会自动启动,通过 netstat 命令可以看到系统已经
监听了 21 端口:
kylin@kylin:~$ sudo netstat -nltp | grep 21
tcp6       0      0 :::21                   :::*                    LISTEN      4714/vsftpd

 如果没有启动,可以手动开启 VSFTPD 服务:

sudo systemctl start vsftpd.service

2.配置用户访问目录

 新建用户主目录:

kylin@kylin:~$ sudo mkdir /home/uftp

 执行完后,在这里 /home/uftp ,就能看到新建的文件夹 uftp 了。

创建登录欢迎文件 

kylin@kylin:~$ sudo touch /home/uftp/welcome.txt

 创建一个用户 uftp

kylin@kylin:~$ sudo useradd -d /home/uftp -s /bin/bash uftp

 为用户 uftp 设置密码 

kylin@kylin:~$ sudo passwd uftp
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

 删除掉 pam.d 中 vsftpd,因为该配置文件会导致使用用户名登录 ftp 失败:

kylin@kylin:~$ sudo rm /etc/pam.d/vsftpd

 限制用户 uftp 只能通过 FTP 访问服务器,而不能直接登录服务器:

kylin@kylin:~$ sudo usermod -s /sbin/nologin uftp

 修改 vsftpd 配置

kylin@kylin:~$ sudo chmod a+w /etc/vsftpd.conf

 修改 /etc/vsftpd.conf 文件中的配置(直接将如下配置添加到配置文件最下方):

# 限制用户对主目录以外目录访问
chroot_local_user=YES

# 指定一个 userlist 存放允许访问 ftp 的用户列表
userlist_deny=NO
userlist_enable=YES

# 记录允许访问 ftp 用户列表
userlist_file=/etc/vsftpd.user_list

# 不配置可能导致莫名的530问题
seccomp_sandbox=NO

# 允许文件上传
write_enable=YES

# 使用utf8编码
utf8_filesystem=YES

 新建文件 /etc/vsftpd.user_list,用于存放允许访问 ftp 的用户:

kylin@kylin:~$ sudo touch /etc/vsftpd.user_list
kylin@kylin:~$ sudo chmod a+w /etc/vsftpd.user_list

 修改 /etc/vsftpd.user_list ,加入刚刚创建的用户:

uftp

 设置访问权限

设置主目录访问权限(只读):

kylin@kylin:~$ sudo chmod a-w /home/uftp

 新建公共目录,并设置权限(读写):

kylin@kylin:~$ sudo mkdir /home/uftp/public && sudo chmod 777 -R /home/uftp/public

 重启vsftpd 服务:

kylin@kylin:~$ sudo systemctl restart vsftpd.service

 3.FTP 服务已安装并配置完成,下面我们来使用该 FTP 服务

ftp://uftp:你的密码@119.29.174.183

 

原文链接:https://cloud.tencent.com/developer/labs/lab/10123

 
posted @ 2018-01-04 00:03    阅读(693)  评论(0编辑  收藏  举报