FTP服务

一、FTP 简介 :

1、FTP使用场合:用于文件的传输;

2、FTP的作用:用于文件的上传和下载;

3、FTP属于tcp协议,端口号:20,21;

21:控制层面,用于账户密码验证,权限的验证;

20:数据层面,用于文件的上传和下载。

4、FTP:匿名、系统、虚拟账户:

**匿名账户:**登录名为ftp或anonymous,不验证密码即可登录;

**系统账户:**本身已经存在的账户、密码做验证。

验证方式:

1、验证的是/etc/passwd和/etc/shadow;

2、验证的是用户列表(用户必须是系统创建),相当于白名单。

默认的root账户不允许登陆。

**虚拟账户:**预定义的列表账户(以前系统从未创建过)。

二、FTP创建匿名账户的过程:

服务器:

1. 关闭防火墙

[root@server ~]# systemctl stop firewalld
[root@server ~]# setenforce 0

2.安装ftp服务

yum -y install vsftpd

3. 相关文件路径

[root@server ~]# cd /etc/vsftpd/
[root@server vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh

vsftpd.conf 配置文件

user_list 用户列表 ,通过修改配置文件去决定用户列表中的用户是否可以登录,即修改黑白名单的登录权限

  • 默认的配置文件参数如下

    [root@server ~]# grep -v "#" /etc/vsftpd/vsftpd.conf | grep -v "^$"   '过滤出有效的执行参数'
    anonymous_enable=YES        	 #允许匿名账户登录
    write_enable=YES				 #写权限的开启,如果想让用户上传文件,此权限也需要
    anon_umask=022                   #设置匿名账户的权限为755
    anon_upload_enable=YES           #允许匿名账户上传
    anon_mkdir_write_enable=YES      #允许匿名账户新建文件或目录
    anon_other_write_enable=YES      #允许匿名账户的其他写权限
    dirmessage_enable=YES
    xferlog_enable=YES
    connect_from_port_20=YES
    xferlog_std_format=YES
    listen=YES						 #监听IPV4地址的请求
    listen_ipv6=NO				     #不监听IPV6地址的请求
    pam_service_name=vsftpd
    userlist_enable=YES
    tcp_wrappers=YES
    

4.创建目录并设定权限

cd /var/ftp/pub
echo “按abc123” > a.txt
chmod -R 755/var/ftp/pub/
chown -R ftp.ftp/var/ftp/pub/

客户机

1.安装ftp服务

yum -y install ftp

2.使用另一台主机,去登陆ftp服务器,使用匿名登陆的方式

[root@client ~]# ftp 192.168.40.13       #开启vsftpd的服务器ip
Connected to 192.168.40.13 (192.168.40.13).
220 (vsFTPd 3.0.2)
Name (192.168.40.13:root): ftp
331 Please specify the password.
Password:                 #密码
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> ls -lh
227 Entering Passive Mode (192,168,40,13,126,187).
150 Here comes the directory listing.
-rwxr-xr-x    1 14       50              7 Oct 31 14:16 a.txt
-rwxr-xr-x    1 14       50              7 Oct 31 14:16 b.txt
226 Directory send OK.
ftp> mkdir 1                      #创建一个目录
257 "/pub/1" created
ftp> put anaconda-ks.cfg   #上传
local: anaconda-ks.cfg remote: anaconda-ks.cfg
227 Entering Passive Mode (192,168,40,13,161,31).
150 Ok to send data.
226 Transfer complete.
2108 bytes sent in 0.0356 secs (59.28 Kbytes/sec)
ftp> ls -lh
227 Entering Passive Mode (192,168,40,13,59,160).
150 Here comes the directory listing.
drwxr-xr-x    2 14       50              6 Oct 31 14:30 1
-rwxr-xr-x    1 14       50              7 Oct 31 14:16 a.txt
-rw-r--r--    1 14       50           2108 Oct 31 14:30 anaconda-ks.cfg
-rwxr-xr-x    1 14       50              7 Oct 31 14:16 b.txt
226 Directory send OK.

3.客户机切换到微软上进行上传测试

在这里插入图片描述
在这里插入图片描述

三、本地账户:

1.创建用户,及测试目录

服务器:

[root@server ~]# useradd lisi
[root@server ~]# passwd lisi
[root@server ~]# useradd zhangsan
[root@server ~]# passwd zhangsan
[root@server ~]# cd /home/zhangsan/
[root@server zhangsan]# vi a.txt
[root@server zhangsan]# cd /home/lisi/
[root@server lisi]# vi b.txt

客户机:
[root@client ~]# vi ttt
[root@client ~]# vi tt2

2.修改配置

vi /etc/vsftpd/vsftpd.conf
[root@server~]# grep -v "#" /etc/vsftpd/vsftpd.conf | grep -v "^$" 
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_local_user=YES
allow_writeable_chroot=YES
listen=YES
listen_ipv6=NO
pam_service_name=vsftpd
userlist_enable=YES             //启用用户列表
tcp_wrappers=YES

3.在客户机上测试

[root@client ~]# ftp 192.168.40.13
Connected to 192.168.40.13 (192.168.40.13).
220 (vsFTPd 3.0.2)
Name (192.168.40.13:root): zhangsan
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls -lh
227 Entering Passive Mode (192,168,40,13,221,38).
150 Here comes the directory listing.
-rw-r--r--    1 0        0               7 Oct 31 16:16 a.txt
226 Directory send OK.
ftp> passive
Passive mode off.
ftp> get a.txt
local: a.txt remote: a.txt
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for a.txt (7 bytes).
226 Transfer complete.
7 bytes received in 2.3e-05 secs (304.35 Kbytes/sec)
ftp> put ttt
local: ttt remote: ttt
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
6 bytes sent in 5.8e-05 secs (103.45 Kbytes/sec)

查看:
服务器

[root@server ~]# cd /home/zhangsan/
[root@server zhangsan]# ll
总用量 8
-rw-r--r-- 1 root     root     7 11月  1 00:16 a.txt
-rw-r--r-- 1 zhangsan zhangsan 6 11月  1 00:56 ttt

客户机
[root@client ~]# ll
总用量 20
-rw-r–r-- 1 root root 7 11月 1 00:55 a.txt

设置白名单:

1.设置本地用户的可登录用户列表(白名单)

vi /etc/vsftpd/user_list
添加允许登录的用户:
zhangsan

2.修改配置

vi /etc/vsftpd/vsftpd.conf
添加:userlist_deny=NO   //只允许用户列表里的用户登录

测试

[root@client ~]# ftp 192.168.40.13
Connected to 192.168.40.13 (192.168.40.13).
220 (vsFTPd 3.0.2)
Name (192.168.40.13:root): lisi
530 Permission denied.
Login failed.
ftp> exit
221 Goodbye.
[root@client ~]# ftp 192.168.40.13
Connected to 192.168.40.13 (192.168.40.13).
220 (vsFTPd 3.0.2)
Name (192.168.40.13:root): zhangsan
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

四、虚拟账户

1.设置虚拟账户列表

vi/etc/vsftpd/vusers.list 
mike 	
123 
john 
234

2.新建虚拟用户账户数据库

cd/etc/vsftpd/
db_load-T-t hash-fusers.isl vusers.db file vusers. db

查看;fie vusers.db

chmod 600/etc/vsftpd/vusers.*ls -lh /etc/vsftpd/vusers. *    //为了安全,修改权限,只让root账户查看

创建虚拟账户

useradd -d /var/ftproot -s /sbin/nologin virtual 
chmod 755/var/ftproot              //宿主目录权限 

创建pam认证

vi/etc/pam.d/vsftpd.vu 
#%PAM-1.0 auth
auth         required       pam_userdb.so    db=/etc/vsftpd/vusers 
account      required       pam userdb.so    db=/etc/vsftpd/vusers 
#auth 对账户名和密码进行认证
#account 对密码的有效期及密码账户的一些权限限定的认证vi/etc/vsftpd/vsftpd. conf

3.修改配置文件

vi /etc/vsftpd/vsftpd.conf

anonymous_enable=NO 	#关闭匿名账户
local_enable=YES 		#启用本地账户,一定要启用,如果禁用的话,虚拟用户则无法登录了
chroot_local_user=YES
guest_enable=YES		#启用虚拟用户
guest_username=virtual 	#指定虚拟用户的宿主用户
pam_service_name=vsftpd. vu #pam认证的文件
anon_world_readable_only=NO		#允许虚拟用户下载
max_clients=400				#最大连接数
max_per_ip=10				#每ip最大可登录数
listen=YES
allow_writeable_chroot=YES
user_config_dir=/etc/vsftpd/vusers_dirl #配置文件
write_enable=YES

4.设置虚拟账户的配置文件

mkdir /etc/vsftpd/vusers_dir/
cd/etc/vsftpd/vusers_dir/
vi mike 			#默认mike只可下载,不能上传,需要上传权限,需要另外指定
anon_upload_enable=YES
anon_mkdir_write_enable=YES write_enable=YES
vi john 			#空文件,只有下载权限
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值