FTP服务
概述:
FTP(File Transfer Protocol),是文件传输协议的简称。用于Internet上的控制文件的双向传输。同时,
它也是一个应用程序(Application),用户可以通过它把自己的PC机与世界各地所有运行FTP协议的服务器相连,
访问服务器上的大量程序和信息。
FTP的主要功能是实现各种操作系统之间的文件交流,建立一个统一的文件传输协议。
ftp:// ##文件传输协议
vsftpd ##FTP服务器包
实验环境:
服务端:server 172.25.254.234
客户端:物理机 172.25.254.34 注意:所有配置都在服务端,而客户端只是用来测试
安装包:
服务端: vsftd
客户端: lftp
1.部署ftp服务
在服务端:
(1).安装FTP服务器包并开启服务
##安装FTP服务器包vsftpd
[root@localhost ~]# yum install -y vsftpd
##打开服务
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl enable vsftpd
(2).添加防火墙策略(或者直接关闭火墙)
[root@localhost ~]# systemctl status firewalld
##添加防火墙策略,让火墙允许ftp服务; --permanent表示永久添加
[root@localhost ~]# firewall-cmd --permanent --add-service=ftp
Success
##重新加载;必须执行,否则不生效
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
(3)关闭selinux(因为selinux会影响后续实验)
##查看selinux的状态
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# vim /etc/sysconfig/selinux
###############
SELINUX=disabled
##必须重启才能生效
[root@localhost ~]# reboot
[root@foundation34 html]# ssh root@172.25.254.234
[root@localhost ~]# getenforce
配置客户端:
(1)安装lftp
##检测该主机已经安装过lftp
[kiosk@foundation34 ~]$ rpm -q lftp
(2).测试:ls不报错即视为连接成功
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxr-xr-x 2 0 0 6 Mar 07 2014 pub
lftp 172.25.254.234:/> exit
@排错:ls时出现Interrupt,即无法连接。
(1)vsftpd服务没有打开
(2)防火墙未关闭,也没有添加防火墙策略
2.ftp服务的基本信息
软件安装包: vsftpd
默认发布目录: /var/ftp
协议接口: 21/tcp
服务配置文件: /etc/vsftpd/vsftpd.conf
报错id的解析:500 ##文件系统权限过大530 ##用户认证失败550 ##服务本身功能未开放 553 ##文件权过小
实验:
##查询软件的配置文件名称
[root@localhost ~]# rpm -qc vsftpd
##/var/ftp/为FTP服务的默认发布目录
[root@localhost ~]# cd /var/ftp/
[root@localhost ftp]# ls
##查看帮助
[kiosk@foundation34 Desktop]$ man 5 vsftpd.conf
3.ftp服务主配置文件参数的设定
@@1.默认匿名用户和本地用户登陆可以登陆
$1.匿名用户登陆
在客户端:
##匿名用户登陆
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxr-xr-x 2 0 0 6 Mar 07 2014 pub
lftp 172.25.254.234:/> exit
$2.本地用户登陆
在服务端:
##建立用户
[root@localhost ~]# id student
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
[root@localhost ~]# id westos
id: westos: no such user
[root@localhost ~]# useradd westos
##更改用户密码
[root@localhost ~]# passwd student
[root@localhost ~]# passwd westos
在客户端:
##本地用户登陆
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u student
Password:
lftp student@172.25.254.234:~> ls
lftp student@172.25.254.234:~> exit
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
lftp westos@172.25.254.234:~> exit
@2.默认本地用户的登陆在用户家目录
在服务端:
[root@localhost ~]# cd /home/student
[root@localhost student]# ls
[root@localhost student]# touch studentfile
[root@localhost student]# ls
studentfile
在客户端:
在服务端:
[root@localhost student]# cd /home/westos
[root@localhost westos]# ls
[root@localhost westos]# touch westosfile{1..3}
[root@localhost westos]# ls
westosfile1 westosfile2 westosfile3
在客户端:
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
@3.默认本地用户可以的登陆、上传、删除、新建目录
##本地用户登陆
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
##上传文件
lftp westos@172.25.254.234:~> put /etc/passwd
3190 bytes transferred
lftp westos@172.25.254.234:~> ls
-rw-r--r-- 1 1001 1001 3190 Oct 31 15:19 passwd
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
##删除文件
lftp westos@172.25.254.234:~> rm passwd
rm ok, `passwd' removed
lftp westos@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
##新建目录
lftp westos@172.25.254.234:~> mkdir hello
mkdir ok, `hello' created
lftp westos@172.25.254.234:~> ls
drwxr-xr-x 2 1001 1001 6 Oct 31 15:20 hello
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
##但不能用使用touch命令 因为ftp服务界面并非支持所有shell中的所有命令
lftp westos@172.25.254.234:~> touch file
Unknown command `touch'.
lftp westos@172.25.254.234:~> exit
@@默认匿名用户不能删除、下载、建立目录
在服务端:
[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# ls
pub
[root@localhost ftp]# cd pub
[root@localhost pub]# ls
[root@localhost pub]# mkdir file{1..3}
[root@localhost pub]# ls
file1 file2 file3
在客户端:
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxr-xr-x 5 0 0 42 Oct 31 15:56 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
lftp 172.25.254.234:/pub> rm file1
rm: Access failed: 550 Permission denied. (file1)
lftp 172.25.254.234:/pub> put /etc/passwd
put: Access failed: 550 Permission denied. (passwd)
lftp 172.25.254.234:/pub> mkdir test
mkdir: Access failed: 550 Permission denied. (test)
lftp 172.25.254.234:/pub> exit
本地用户参数设定:
(1).本地用户是否可以登陆
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
################
local_enable=NO ##不允许本地用户登陆
[root@localhost ~]# systemctl restart vsftpd
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
ls: Login failed: 530 This FTP server is anonymous only.
lftp westos@172.25.254.234:~> exit
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
local_enable=YES ##允许本地用户登陆
[root@localhost ~]# systemctl restart vsftpd
(2).指定本地用户家目录
[root@localhost ~]# mkdir /westos
[root@localhost ~]# touch /westos/linux{1..3}
[root@localhost ~]# ll /westos
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
local_root=/westos #更改本地用户家目录为/westos
[root@localhost ~]# systemctl restart vsftpd
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 31 16:07 linux1
-rw-r--r-- 1 0 0 0 Oct 31 16:07 linux2
-rw-r--r-- 1 0 0 0 Oct 31 16:07 linux3
lftp westos@172.25.254.234:~> exit
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u student
Password:
lftp student@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 31 16:07 linux1
-rw-r--r-- 1 0 0 0 Oct 31 16:07 linux2
-rw-r--r-- 1 0 0 0 Oct 31 16:07 linux3
lftp student@172.25.254.234:~> exit
[root@localhost ~]# cd /home/westos
[root@localhost westos]# ls
hello westosfile1 westosfile2 westosfile3
[root@localhost westos]# cd /home/student
[root@localhost student]# ls
studentfile
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
################
#local_root=/westos
[root@localhost student]# systemctl restart vsftpd
(3).指定本地用户上传文件的权限 (默认为644)
##默认权限为644
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
drwxr-xr-x 2 1001 1001 6 Oct 31 15:20 hello
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
lftp westos@172.25.254.234:~> put /etc/passwd
3190 bytes transferred
lftp westos@172.25.254.234:~> ls
drwxr-xr-x 2 1001 1001 6 Oct 31 15:20 hello
-rw-r--r-- 1 1001 1001 3190 Oct 31 16:23 passwd
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
lftp westos@172.25.254.234:~> exit
[root@localhost student]# vim /etc/vsftpd/vsftpd.conf
####################
24 local_umask=077 ##更改本地用户上传文件的权限
[root@localhost student]# systemctl restart vsftpd
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
drwxr-xr-x 2 1001 1001 6 Oct 31 15:20 hello
-rw-r--r-- 1 1001 1001 3190 Oct 31 16:23 passwd
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
lftp westos@172.25.254.234:~> put /etc/inittab
510 bytes transferred
lftp westos@172.25.254.234:~> ls
drwxr-xr-x 2 1001 1001 6 Oct 31 15:20 hello
-rw------- 1 1001 1001 510 Oct 31 16:26 inittab
-rw-r--r-- 1 1001 1001 3190 Oct 31 16:23 passwd
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
lftp westos@172.25.254.234:~> exit
还原:
[root@localhost student]# vim /etc/vsftpd/vsftpd.conf
####################
#local_root=/westos
[root@localhost student]# systemctl restart vsftpd
匿名用户设定:
(1).匿名用户是否可以登陆
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
12 anonymous_enable=NO #不允许匿名用户登陆
[root@localhost ~]# systemctl restart vsftpd
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
Interrupt
lftp 172.25.254.234:~> exit
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
12 anonymous_enable=YES #允许匿名用户登陆
[root@localhost ~]# systemctl restart vsftpd
(2).如何让匿名用户可以put上传文件
@默认匿名用户不能使用put上传
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
##############
29 anon_upload_enable=YES #取消注释即可,允许匿名用户可以上传
[root@localhost ~]# systemctl restart vsftpd.service
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxr-xr-x 5 0 0 42 Oct 31 15:56 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
lftp 172.25.254.234:/pub> put /etc/passwd
put: Access failed: 553 Could not create file. (passwd) #本地文件权限过小
lftp 172.25.254.234:/pub> exit
##更改文件组和权限
[root@localhost ~]# ll /var/ftp
total 0
drwxr-xr-x. 5 root root 42 Oct 31 11:56 pub
[root@localhost ~]# chgrp ftp /var/ftp/pub/
[root@localhost ~]# chmod g+w /var/ftp/pub/
[root@localhost ~]# ll /var/ftp
total 0
drwxrwxr-x. 5 root ftp 42 Oct 31 11:56 pub
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 5 0 50 42 Oct 31 15:56 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
lftp 172.25.254.234:/pub> put /etc/passwd
3190 bytes transferred
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
-rw------- 1 14 50 3190 Oct 31 16:44 passwd
lftp 172.25.254.234:/pub> exit
(3).如何让匿名用户可以get下载文件
默认匿名用户不能下载文件
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
30 anon_world_readable_only=NO #允许匿名用户下载
[root@localhost ~]# systemctl restart vsftpd.service
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 5 0 50 55 Oct 31 16:44 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
-rw------- 1 14 50 3190 Oct 31 16:44 passwd
lftp 172.25.254.234:/pub> get passwd
3190 bytes transferred
lftp 172.25.254.234:/pub> exit
[kiosk@foundation34 ~]$ ls
Desktop Downloads passwd Pictures PycharmProjects Videos westos
Documents Music perl5 Public Templates Wallpapers
(3)如何让匿名用户可以删除文件默认匿名用户不能删除[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
31 anon_other_write_enable=YES #允许匿名用户删除
[root@localhost ~]# systemctl restart vsftpd.service
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 5 0 50 55 Oct 31 16:44 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
-rw------- 1 14 50 3190 Oct 31 16:44 passwd
lftp 172.25.254.234:/pub> rm passwd
rm ok, `passwd' removed
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
lftp 172.25.254.234:/pub> exit
(4)如何让匿名用户可以建立目录
默认匿名用户不能建立目录
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
anon_mkdir_write_enable=YES ##取消注释即可,允许匿名用户建立目录
[root@localhost ~]# systemctl restart vsftpd.service
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 5 0 50 42 Oct 31 16:58 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> mkdir westos
mkdir ok, `westos' created
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
drwx------ 2 14 50 6 Oct 31 17:02 westos
lftp 172.25.254.234:/pub> exit
(5)更改匿名用户家目录
[root@localhost ~]# mkdir /hello
[root@localhost ~]# touch /hello/lee{1..3}
[root@localhost ~]# ls /hello/
lee1 lee2 lee3
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
30 anon_root=/linux ##更改匿名用户家目录
[root@localhost ~]# systemctl restart vsftpd.service
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 31 17:06 lee1
-rw-r--r-- 1 0 0 0 Oct 31 17:06 lee2
-rw-r--r-- 1 0 0 0 Oct 31 17:06 lee3
lftp 172.25.254.234:/> exit
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
#anon_root=/linux
[root@localhost ~]# systemctl restart vsftpd.service
(6)更改匿名用户上传文件默认权限
##默认权限为600
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 6 0 50 55 Oct 31 17:02 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
drwx------ 2 14 50 6 Oct 31 17:02 westos
lftp 172.25.254.234:/pub> exit
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
31 anon_umask=022
[root@localhost ~]# systemctl restart vsftpd.service
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 6 0 50 55 Oct 31 17:02 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
drwx------ 2 14 50 6 Oct 31 17:02 westos
lftp 172.25.254.234:/pub> put /etc/inittab
510 bytes transferred
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
-rw-r--r-- 1 14 50 510 Oct 31 17:14 inittab
drwx------ 2 14 50 6 Oct 31 17:02 westos
lftp 172.25.254.234:/pub> exit
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
#anon_umask=022
[root@localhost ~]# systemctl restart vsftpd.service
(7).修改匿名用户上传文件使用身份(文件所有人)及文件权限
[root@localhost ~]# id student
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
chown_uploads=YES ##允许对上传文件做更改
chown_username=student ##更改文件所有人
chown_upload_mode=0644 ##更改文件权限
[root@localhost ~]# systemctl restart vsftpd
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 6 0 50 82 Oct 31 17:17 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
-rw-r--r-- 1 14 50 510 Oct 31 17:14 inittab
-rw------- 1 14 50 3190 Oct 31 17:17 passwd
drwx------ 2 14 50 6 Oct 31 17:02 westos
lftp 172.25.254.234:/pub> put /etc/group
1195 bytes transferred
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
-rw-r--r-- 1 1000 50 1195 Oct 31 23:33 group
-rw-r--r-- 1 14 50 510 Oct 31 17:14 inittab
-rw------- 1 14 50 3190 Oct 31 17:17 passwd
drwx------ 2 14 50 6 Oct 31 17:02 westos
lftp 172.25.254.234:/pub> exit
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
################
#chown_uploads=YES
#chown_username=student
#chown_upload_mode=0644
[root@localhost ~]# systemctl restart vsftpd
匿名用户和本地用户相同参数设定:
(1).本地用户和匿名用户是否可写(mkdir rm put)
默认匿名用户不可写
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
19 write_enable=NO ##不允许本地用户和匿名用户写
[root@localhost ~]# systemctl restart vsftpd
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 6 0 50 94 Oct 31 23:33 pub
lftp 172.25.254.234:/> mkdir hello
mkdir: Access failed: 550 Permission denied. (hello)
lftp 172.25.254.234:/> rm pub
rm: Access failed: 550 Permission denied. (pub)
lftp 172.25.254.234:/> put /etc/passwd
put: Access failed: 550 Permission denied. (passwd)
lftp 172.25.254.234:/> exit[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
-rw-r--r-- 1 1001 1001 1195 Oct 31 23:54 group
drwxr-xr-x 2 1001 1001 6 Oct 31 15:20 hello
-rw------- 1 1001 1001 510 Oct 31 16:26 inittab
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
lftp westos@172.25.254.234:~> mkdir haha
mkdir: Access failed: 550 Permission denied. (haha)
lftp westos@172.25.254.234:~> rm /etc/group
rm: Access failed: 550 Permission denied. (/etc/group)
lftp westos@172.25.254.234:~> put /etc/passwd
put: Access failed: 550 Permission denied. (passwd)
lftp westos@172.25.254.234:~> exit
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
19 write_enable=YES
[root@localhost ~]# systemctl restart vsftpd
(2).限速
[kiosk@foundation34 Desktop]$ dd if=/dev/zero of=/tmp/file bs=1M count=1000
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 6 0 50 94 Oct 31 23:33 pub
lftp 172.25.254.234:/> cd pub/
lftp 172.25.254.234:/pub> ls
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
-rw-r--r-- 1 1000 50 1195 Oct 31 23:33 group
-rw-r--r-- 1 14 50 510 Oct 31 17:14 inittab
-rw------- 1 14 50 3190 Oct 31 17:17 passwd
drwx------ 2 14 50 6 Oct 31 17:02 westos
lftp 172.25.254.234:/pub> put /tmp/file
1048576000 bytes transferred in 34 seconds (29.44M/s)
lftp 172.25.254.234:/pub> exit
1048576000 bytes transferred in 34 seconds (29.44M/s)
lftp 172.25.254.234:/pub> exit
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
32 anon_max_rate=102400 ##限制速度
[root@localhost ~]# systemctl restart vsftpd.service
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 6 0 50 4096 Nov 01 00:14 pub
lftp 172.25.254.234:/> cd pub
lftp 172.25.254.234:/pub> ls
-rw------- 1 14 50 131595856 Nov 01 00:21 file
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file1
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file2
drwxr-xr-x 2 0 0 6 Oct 31 15:56 file3
-rw-r--r-- 1 1000 50 1195 Oct 31 23:33 group
-rw-r--r-- 1 14 50 510 Oct 31 17:14 inittab
-rw------- 1 14 50 3190 Oct 31 17:17 passwd
drwx------ 2 14 50 6 Oct 31 17:02 westos
lftp 172.25.254.234:/pub> put /tmp/file
Interrupt
lftp 172.25.254.234:/pub> exit
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
32 #anon_max_rate=102400
[root@localhost ~]# systemctl restart vsftpd.service
(3).限制最大连接数(防止过多用户登录,系统崩溃)
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
33 max_clients=1
[root@localhost ~]# systemctl restart vsftpd
[kiosk@foundation34 ~]$ lftp 172.25.254.234
lftp 172.25.254.234:~> ls
drwxrwxr-x 6 0 50 4096 Nov 01 00:27 pub
lftp 172.25.254.234:/>
连接另一个主机:
[root@foundation34 ~]# ssh root@172.25.254.134
root@172.25.254.134's password:
Last login: Wed Oct 31 20:32:59 2018 from 172.25.254.66
[root@localhost ~]# lftp 172.25.254.234
lftp 172.25.254.234:~> ls
Interrupt
lftp 172.25.254.234:~> exit
还原:
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
#max_clients=1
[root@localhost ~]# systemctl restart vsftpd
(4).本地用户黑名单的设定
如果本地用户都无法登陆,那么匿名用户就更不能登陆了
@1.永久性黑名单: ftpusers (无论任何情况下都是黑名单)
[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
##即改即生效
[root@localhost vsftpd]# vim ftpusers
###################
westos
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
ls: Login failed: 530 Login incorrect.
lftp westos@172.25.254.234:~> exit
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u student
Password:
lftp student@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 31 15:16 studentfile
lftp student@172.25.254.234:~> exit
还原:
[root@localhost vsftpd]# vim ftpusers
###################
删除westos
@2.临时性黑名单: user_list (可以变为白名单)
[root@localhost vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
[root@localhost vsftpd]# pwd
/etc/vsftpd
[root@localhost vsftpd]# vim user_list
###################
student
[kiosk@foundation66 ~]$ lftp 172.25.254.234 -u student
Password:
lftp student@172.25.254.234:~> ls
ls: Login failed: 530 Permission denied.
lftp student@172.25.254.234:~> exit
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
-rw-r--r-- 1 1001 1001 1195 Oct 31 23:54 group
drwxr-xr-x 2 1001 1001 6 Nov 01 00:09 haha
drwxr-xr-x 2 1001 1001 6 Oct 31 15:20 hello
-rw-r--r-- 1 1001 1001 3190 Nov 01 00:09 passwd
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile1
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile2
-rw-r--r-- 1 0 0 0 Oct 31 15:18 westosfile3
lftp westos@172.25.254.234:~> exit
(5).本地用户白名单的设定
[root@localhost vsftpd]# cat user_list
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf
###################
userlist_deny=NO #不被拒绝,即为允许;允许user_list文件中的用户登陆
[root@localhost vsftpd]# systemctl restart vsftpd
##发现在user_list文件中的用户变成了白名单
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u student
Password:
lftp student@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 31 15:16 studentfile
lftp student@172.25.254.234:~> exit
##也就是说不在user_list文件中的用户均不能登陆
[kiosk@foundation34 ~]$ lftp 172.25.254.234 -u westos
Password:
lftp westos@172.25.254.234:~> ls
ls: Login failed: 530 Permission denied.
lftp westos@172.25.254.234:~> exit
@注意:如果某个用户同时出现在白名单和永久性黑名单里,此时该用户在黑名单里生效,即该用户不能登陆
[root@localhost vsftpd]# cat user_list
[root@localhost vsftpd]# vim ftpusers
###################
Student
[kiosk@foundation66 ~]$ lftp 172.25.254.234 -u student
Password:
lftp student@172.25.254.234:~> ls
ls: Login failed: 530 Login incorrect.
lftp student@172.25.254.234:~> exit
还原:
[root@localhost vsftpd]# vim user_list
删除 studnet[root@localhost vsftpd]# vim ftpusers
删除 student[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf
###################
#userlist_deny=NO
[root@localhost vsftpd]# systemctl restart vsftpd
虚拟用户的设定
(1).建立允许虚拟用户并允许其登陆
[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
##设定虚拟用户及用户密码
[root@localhost vsftpd]# vim loginusers
###################
westos1
111
westos2
222
westos3
333
##哈希加密
[root@localhost vsftpd]# db_load -T -t hash -f loginusers loginusers.db
[root@localhost vsftpd]# ls
##添加用户认证和密码认证
[root@localhost vsftpd]# vim /etc/pam.d/ftpauth
##################
account required pam_userdb.so db=/etc/vsftpd/loginusers
帐号 验证 程序&(插件) 对比文件(本文件后边会自动添加.db)
auth required pam_userdb.so db=/etc/vsftpd/loginusers
密码认证
##生成虚拟用户并允许其登陆
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf
###################
pam_service_name=ftpauth #设定虚拟用户认证文件
guest_enable=YES #允许虚拟用户登陆
[root@localhost vsftpd]# systemctl restart vsftpd
测试:
##默认虚拟用户身份为ftp
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos1
Password:
lftp westos1@172.25.254.234:~> ls
drwxrwxr-x 3 0 50 69 Oct 28 09:17 pub
lftp westos1@172.25.254.234:/> exit
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos2
Password:
lftp westos2@172.25.254.234:~> ls
drwxrwxr-x 3 0 50 69 Oct 28 09:17 pub
lftp westos2@172.25.254.234:/> exit
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos3
Password:
lftp westos3@172.25.254.234:~> ls
drwxrwxr-x 3 0 50 69 Oct 28 09:17 pub
lftp westos3@172.25.254.234:/> exit
(2).更改所有虚拟用户的用户身份
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf
###################
guest_username=student #指定虚拟用户身份
[root@localhost vsftpd]# systemctl restart vsftpd
测试:
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos1
Password:
lftp westos1@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 28 06:30 studentfile
lftp westos1@172.25.254.234:/> exit
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos2
Password:
lftp westos2@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 28 06:30 studentfile
lftp westos2@172.25.254.234:/> exit
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos3
Password:
lftp westos3@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 28 06:30 studentfile
lftp westos3@172.25.254.234:/> exit
排错1
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos1
Password:
lftp westos1@172.25.254.234:~> ls
##500表示用户权限过大
ls: Login failed: 500 OOPS: vsftpd: refusing to run with writable root inside chroot()
lftp westos1@172.25.254.234:~> exit
解决方案:
[root@localhost vsftpd]# cd /home
[root@localhost home]# ll
total 8
drwx------. 4 student student 4096 Oct 31 11:16 student
drwx------ 6 westos westos 4096 Oct 31 20:09 westos
[root@localhost home]# chmod u-w /home/*
[root@localhost home]# ll
total 8
dr-x------. 4 student student 4096 Oct 31 11:16 student
dr-x------ 6 westos westos 4096 Oct 31 20:09 westos[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos1
Password:
lftp westos1@172.25.254.234:~> ls
-rw-r--r-- 1 0 0 0 Oct 28 06:30 studentfile
lftp westos1@172.25.254.234:/> exit
(3).分别指定虚拟用户家目录
## -p表示同时建立多个目录,即建立/ftphome目录并且在该目录下建立westos1,westos2,westos3目录
[root@localhost ~]# mkdir -p /ftphome/westos{1..3}
[root@localhost ~]# mkdir -p /ftphome/westos1/westos1data
[root@localhost ~]# mkdir -p /ftphome/westos2/westos2data
[root@localhost ~]# mkdir -p /ftphome/westos3/westos3data
##发现 $USER 可以区分用户身份
[root@localhost ~]# su - student
Last login: Sun Oct 28 02:27:50 EDT 2018 on pts/0
[student@localhost ~]$ pwd
/home/student
[student@localhost ~]$ echo $USER
student
[student@localhost ~]$ exit
logout
[root@localhost ~]# su - westos
Last login: Sun Oct 28 02:27:41 EDT 2018 on pts/0
[westos@localhost ~]$ pwd
/home/westos
[westos@localhost ~]$ echo $USER
westos
[westos@localhost ~]$ exit
Logout
##分别设定虚拟用户家目录
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
local_root=/ftphome/$USER ##独立虚拟用户家目录
user_sub_token=$USER ##告诉系统$USER不是串普通字符,而是一个可以区分用户身份变量
[root@localhost ~]# systemctl restart vsftpd
测试:
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos1
Password:
lftp westos1@172.25.254.234:~> ls
drwxr-xr-x 2 0 0 6 Nov 03 03:31 westos1data
lftp westos1@172.25.254.234:/> exit
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos2
Password:
lftp westos2@172.25.254.234:~> ls
drwxr-xr-x 2 0 0 6 Nov 03 03:31 westos2data
lftp westos2@172.25.254.234:/> exit
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos3
Password:
lftp westos3@172.25.254.234:~> ls
drwxr-xr-x 2 0 0 6 Nov 03 03:31 westos3data
lftp westos3@172.25.254.234:/> exit
(4).只允许单个虚拟用户拥有某权限
以只允许westos1可以上传文件为例:
[kiosk@foundation34 Desktop]$ man 5 vsftpd.conf
[root@localhost ~]# mkdir -p /etc/vsftpd/user_conf
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
###############
#anon_upload_enable=YES ##必须注释此行,否则所有虚拟用户均可写user_config_dir=/etc/vsftpd/user_conf
[root@localhost ~]# touch /etc/vsftpd/user_conf/westos1
[root@localhost ~]# vim /etc/vsftpd/user_conf/westos1
###############
anon_upload_enable=YES ##仅允虚拟用户westos1可以上传
##更改文件权限
[root@localhost ~]# ll /ftphome/westos*
[root@localhost ~]# chmod 777 /ftphome/westos*/*
[root@localhost ~]# ll /ftphome/westos*
[root@localhost ~]# systemctl restart vsftpd
测试:
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos1
Password:
lftp westos1@172.25.254.234:~> ls
drwxrwxrwx 2 0 0 6 Nov 03 05:11 westos1data
lftp westos1@172.25.254.234:/> cd westos1data/
lftp westos1@172.25.254.234:/westos1data> ls
lftp westos1@172.25.254.234:/westos1data> put /etc/passwd
2367 bytes transferred
lftp westos1@172.25.254.234:/westos1data> ls
-rw------- 1 1000 1000 2367 Nov 03 05:15 passwd
lftp westos1@172.25.254.234:/westos1data> exit
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos2
Password:
lftp westos2@172.25.254.234:~> ls
drwxrwxrwx 2 0 0 6 Nov 03 05:11 westos2data
lftp westos2@172.25.254.234:/> cd westos2data/
lftp westos2@172.25.254.234:/westos2data> ls
##550表示功能本身功能未开启
lftp westos2@172.25.254.234:/westos2data> put /etc/passwd
put: Access failed: 550 Permission denied. (passwd)
lftp westos2@172.25.254.234:/westos2data> exit
[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u westos3
Password:
lftp westos3@172.25.254.234:~> ls
drwxrwxrwx 2 0 0 6 Nov 03 05:11 westos3data
lftp westos3@172.25.254.234:/> cd westos3data/
lftp westos3@172.25.254.234:/westos3data> ls
lftp westos3@172.25.254.234:/westos3data> put /etc/passwd
put: Access failed: 550 Permission denied. (passwd)
lftp westos3@172.25.254.234:/westos3data> exit
排错思想:
如果报错是530认证失败那么就查看认证信息日志##查看认证信息
[root@localhost ~]# > /var/log/secure[kiosk@foundation34 Desktop]$ lftp 172.25.254.234 -u student
Password:
lftp student@172.25.254.234:~> ls
ls: Login failed: 530 Login incorrect.
lftp student@172.25.254.234:~> exit[root@localhost ~]# cat /var/log/secure