一起来学linux:FTP服务器搭建
首先安装vsftpd: apt install vsftpd
有下面几个重要的配置文件:
1 /etc/vsftpd.conf. 这个是vsftpd的配置文件。通过“参数=设置值”的方式来设置的。
2 /etc/pam.d/vsftpd 这个是vsftpd使用PAM模块时的配置文件。主要用来作为身份认证用的
下面file后面接的内容就是限制用户无法使用vsftpd的意思
root@zhf-linux:/etc# cat /etc/pam.d/vsftpd
# Standard behaviour for ftpd(8).
auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
查看这个文件可以看到有如下的用户都不能登陆FTP。其中就包括root用户
root@zhf-linux:/etc# cat /etc/ftpusers
# /etc/ftpusers: list of users disallowed FTP access. See ftpusers(5).
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
nobody
3 /etc/vsftpd/user_list 这个文件是否生效和vsftpd.conf里面的配置有关,如果userlist_deny=YES.则userlist_file指向的文件里面的用户无法登陆。
4 /etc/vsftpd.chroot_list:可以将某些帐号的用户chroot建立在他们的默认用户主目录下。这个文件的生效取决与chroot_list_enable和chroot_list_file两个参数有关
启动FTP:
/etc/init.d/vsftpd start
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220 (vsFTPd 3.0.3)
Name (192.168.0.11:root): zhf
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
可以看到zhf用户可以登陆进。但是root用户就会失败。因为在/etc/ftpusers中有root用户
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220 (vsFTPd 3.0.3)
Name (192.168.0.11:root): root
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
将/etc/ftpusers中的root用户删除掉root就可以登陆了。
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220 (vsFTPd 3.0.3)
Name (192.168.0.11:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
前面root用户禁止登陆是PAM模块拦截的。我们可以在vsftpd.conf设置禁止登陆的用户
在vsftpd.conf中添加如下信息
userlist_enable=YES
userlist_deny=YES 这个只有在userlist_enable=YES的时候才有效
userlist_file=/etc/vsftpd.user_list
然后在/etc下新建vsftpd.user_list文件并在其中添加root并且重启FTP服务。可以看到root用户登陆失败
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220 (vsFTPd 3.0.3)
Name (192.168.0.11:root): root
530 Permission denied.
Login failed.
我们发现一个问题,用户在登陆FTP服务器后,可以随意切换目录,并不一定被限制在主目录下。用户可以访问服务器的任意文件。这种方式极不安全,因为用户可以任意修改文件
ftp> cd /etc
250 Directory successfully changed.
因此我们需要将用户限制在主目录下,无法切换到其他目录。这就需要用到chroot功能
chroot_local_user=YES 是否将用户限制在自己的用户主目录之内如果是yes,代表用户默认就会被chroot。如果是no,则默认三没有chroot
chroot_list_enable=YES 设置为yes代表下面chroot_list_file指向的文件里的用户具备切换到其他目录的权限
chroot_list_file=/etc/vsftpd.chroot_list
但是我们用root用户登陆的时候,却提示500 OOPS: vsftpd: refusing to run with writable root inside chroot()
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220 (vsFTPd 3.0.3)
Name (192.168.0.11:root): root
331 Please specify the password.
Password:
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
这个错误的原因是chroot目录不具备写的权限。只需要在vsftpd.conf中设置allow_writeable_chroot=YES就可以了。设置后好重启
这个时候可以正常登陆,此时用cd /etc切换目录,提示失败。
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220 (vsFTPd 3.0.3)
Name (192.168.0.11:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd /etc
550 Failed to change directory.
而用zhf登陆后修改是可以的。原因在于zhf存在于vsftpd.chroot_list中且chroot_list_enable=YES
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220 (vsFTPd 3.0.3)
Name (192.168.0.11:root): zhf
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd /etc
250 Directory successfully changed.
设置登陆后的显示信息
在vsftpd.conf中添加banner_file。banner_file=/etc/vsftpd/login.txt。并在login.txt中填上需要的信息
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220-欢迎来到FTP服务器。技术问题可以联系枫叶
220
匿名用户登陆:
前面都是通过实体用户登陆的。但是在一些学校的FTP服务器是可以支持匿名用户访问的。下面来看下匿名用户访问的设置
在vsftpd.conf中添加如下的设置
anonymous_enable=YES
no_anon_password=YES
下面这几个三设置上传或者是建立目录的权限。
anon_other_write_enable=YES
anon_mkdir_write_enable=YES
anon_upload_enable=YES
登陆的时候输入anonymous就可以直接登陆了。
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220-欢迎来到FTP服务器。技术问题可以联系枫叶
220
Name (192.168.0.11:root): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
对于匿名登陆用户的路径可以用finger ftp来查看,如下显示为/srv/ftp/。因此需要把下载的文件都拷贝到这个文件下面。
root@zhf-linux:/srv/ftp# finger ftp
Login: ftp Name: ftp daemon
Directory: /srv/ftp Shell: /bin/false
Never logged in.
No mail.
No Plan.
在这个文件下面新建linux文件夹。登陆后就可以查看。
root@zhf-virtual-machine:~# ftp 192.168.0.11
Connected to 192.168.0.11.
220-欢迎来到FTP服务器。技术问题可以联系枫叶
220
Name (192.168.0.11:root): anonymous
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Nov 15 19:52 linux
226 Directory send OK.
最后来看下FTP登陆时候记录的日志,这些日志都存放在/var/log/vsftpd/log中,前提是在vsftpd.conf中设置了vsftpd_log_file=/var/log/vsftpd.log
Wed Nov 15 19:57:56 2017 [pid 8273] CONNECT: Client "::ffff:192.168.0.9"
Wed Nov 15 19:58:00 2017 [pid 8271] [root] OK LOGIN: Client "::ffff:192.168.0.9"
Wed Nov 15 19:58:47 2017 [pid 8277] [root] OK DOWNLOAD: Client "::ffff:192.168.0.9", "/dead.letter", 110 bytes, 4.81Kbyte/sec
可以看到登陆的信息以及下载的大小和速率
一起来学linux:FTP服务器搭建的更多相关文章
- Linux FTP服务器搭建与使用
一.vsftpd说明 LINUX下实现FTP服务的软件很多,最常见的有vsftpd,Wu-ftpd和Proftp等.Red Hat Enterprise Linux中默认安装的是vsftpd. 访问F ...
- linux ftp服务器搭建
作为服务器的机器IP:192.168.124.129 主机名:Centos 操作系统:CentOS 5.5 需求:匿名用户可以下载公共目录里边内容,本地用户登录有rwx权限 软件安装 1. 准备测 ...
- 《Linux下FTP服务器搭建及FTP使用》
.LOGAndy:mxtd114 <Linux下FTP服务器搭建> 0.root登录 1.安装ftp # yum -y install ftp 2.安装vsftpd # yum -y in ...
- Linux CentOS 6.5 下 vsftpd ftp服务器搭建
Linux CentOS 6.5 下 vsftpd ftp服务器搭建 by:授客 QQ:1033553122 操作系统环境:CentOS 6.5-x86_64 下载地址:http://www.ce ...
- Linux之匿名FTP服务器搭建
FTP(File Transfer Protocol)是在服务器与客户端进行文件传输的一种传输协议.本次介绍的是vsftpd的软件体验ftp服务. FTP服务器默认情况下依据用户登录情况分为三种不同的 ...
- Linux 之 FTP服务器搭建
FTP服务器搭建 参考教程:[千峰教育] 1.关闭防火墙: service iptables stop 2.关闭Selinux setenforce 0 3.安装所需要依赖及编译工具 yum inst ...
- Linux中ftp服务器搭建
一.FTP工作原理 (1)FTP使用端口 [root@localhost ~]# cat /etc/services | grep ftp ftp-data 20/tcp #数据链路:端口20 ftp ...
- FTP-Linux中ftp服务器搭建
一.FTP工作原理 (1)FTP使用端口 [root@localhost ~]# cat /etc/services | grep ftp ftp-data 20/tcp #数据链路:端口20 ftp ...
- centos7 配置ftp服务器搭建(匿名访问,以及本地登录)
大家好,今天来给大家分享一个基于centos 7的ftp服务器搭建 实现功能:匿名访问,本地登录 查看系统版本: [root@localhost ~]# cat /etc/redhat-release ...
- 记一次ftp服务器搭建走过的坑
记一次ftp服务器搭建走过的坑 1.安装 ①下载 wget https://security.appspot.com/downloads/vsftpd-3.0.3.tar.gz #要FQ ②解压 ta ...
随机推荐
- html5(拖拽3)
<!DOCTYPE html"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ...
- 编译Caffe(ubuntu-15.10-desktop-amd64,无Cuda)
编译环境 VMWare Workstation 12 Player ubuntu-15.10-desktop-amd64 cpu 4700mq,给vm分配了6个核心+4GB内存+80GB硬盘 编译步骤 ...
- 初级Springboot(一)
初级Springboot(一) 作者 : Stanley 罗昊 [转载请注明出处和署名,谢谢!] 一.了解Springboot 做Java开发的小伙伴都知道,我们在做项目的时候,需要去写大量的配置文件 ...
- BZOJ——2438: [中山市选2011]杀人游戏
http://www.lydsy.com/JudgeOnline/problem.php?id=2438 Description 一位冷血的杀手潜入 Na-wiat,并假装成平民.警察希望能在 N 个 ...
- ionic build Android错误记录 error in opening zip file
0.写在前头 运行 :cordova requirements Requirements check results for android: Java JDK: installed 1.8.0 An ...
- linux几种常见的文件内容查找和替换命令
作为一个以前没怎么接触过linux的小白,开始使用linux,各种不习惯,这周遇到一个文件内容测查找和替换的需求.学习了以下几种实现方式: 1.vi命令下的查找和替换 1.1 vi下的查找 /patt ...
- 配置laravel的nginx站点
server{}配置 server{ #端口配置 listen 80; #域名配置 server_name laravel.cc; index index.php index.html index.h ...
- Android gradle 相关配置
有时候我们需要重命名输出apk文件名,在Android studio 3.0以前我们是这样写的: applicationVariants.all { variant -> variant.out ...
- module has no attribute 'seq2seq'
tensorflow 中tf.nn.seq2seq.sequence_loss_by_example to tf.contrib.legacy_seq2seq.sequence_loss_by_exa ...
- Direct2D教程(十二)图层
什么是Layers? Layer,中文译成图层,在Direct2D中可以用来完成一些特殊效果,使用Layer的时候,先将Layer Push到render target,然后进行绘制,此时是直接绘制在 ...