Ubuntu18.04下FTP服务器搭建
Ubuntu18.04 换源
使用apt下载vsftp时显示找不到package,因此考虑使用apt-get update命令进行更新。但Ubuntu原有的源是国外的镜像源,下载速度很慢,需要更换成为国内的镜像源。Ubuntu18.04提供图形化界面用于换源,但本文依然使用传统更改sources.list配置文件的方式实现换源。
cd /etc/apt/
cp sources.list sources.list_backup #备份
sudo gedit sources.list
本文替换为阿里源,将sources.list内容替换为以下内容:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
配置文件更改保存后执行以下命令后,换源成功:
sudo apt-get update
sudo apt-get upgrade
ftp服务器搭建
- 下载安装vsftpd:
sudo apt-get install vsftpd
- 下载安装net-tools,方便之后使用ifconfig命令查看服务器的IP地址:
sudo apt-get install net-tools
- vsftpd的配置文件默认在/etc/vsftpd.conf中,修改配置,允许匿名登录。将含有anon或anonymous的参数前面的#去掉,并将参数值改为YES。每次修改配置文件后需要重启vsftpd(!!!):
service vsftpd start #开启服务
service vsftpd stop #关闭服务
service vsftpd restart #重启服务
使用以下命令可以查看ftp服务是否处于开启状态,若有显示/usr/sbin/vsftpd,则服务已经开启:
ps -ef|grep ftp
- 在/etc目录下建立一个vsftpd.chroot_list文件,并设置用户名和密码:
cd /etc
sudo gedit vsftpd.chroot_list
###vsftpd.chroot_list文件###
admin
123456
- 使用ifconfig命令查看服务器IP地址,在客户机端使用命令向服务器发起连接请求:
ftp 192.168.79.130 #IP地址
按照提示分别输入在上一步中设置的用户名和密码,显示连接成功。
- 经过上传和下载尝试,发现本文搭建后的ftp服务器默认公共目录为/home,因此考虑更换公共目录。在配置文件vsftpd.conf中,添加以下内容:
local_root=/usr/ftp_file #自定义目录
chroot_local_user=YES
anon_root=/usr/ftp_file #自定义目录
重启vsftpd,并修改自定义自定义目录的权限,使得用户可以上传和下载公共目录下的文件(若上传或下载文件时显示553: Could not create file错误,即权限问题,可以考虑使用以下命令后重试):
sudo chmod 777 /usr/ftp_file