ftp服务基础部分

FTP学习

FTP数据连接模式

ftp有2种数据连接模式:命令连接和数据连接

命令连接:是指文件管理类命令,始终在线的持久性连接,直到用户退出登录为止
数据连接:是指数据传输,按需创建及关闭的连接

其中数据连接需要关注的有2点,一是数据传输格式,二是数据传输模式

数据传输格式有以下两种:

文件传输
二进制传输

数据传输模式也有2种:

主动模式:由服务器端创建数据连接
被动模式:由客户端创建数据连接

用户认证

ftp的用户主要有三种:

虚拟用户:仅用于访问某特定服务中的资源
系统用户:可以登录系统的真实用户
匿名用户

具体实例

1.安装vsftpd
2.配置匿名用户ftp
3.配置虚拟用户ftp
4.配置系统用户ftp

配置匿名用户FTP

//安装vsftpd在这里就不过多演示了,但是要记得启动服务
//在配置匿名用户时候,只需要在配置文件中修改就可以了
[root@zlb9 ~]# vim /etc/vsftpd/vsftpd.conf 

# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES   //这里注意要设置成yes
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
anon_umask=022   //这里设置了匿名用户的遮盖码
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
anon_upload_enable=YES   //将这里的注释取消掉
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
anon_other_write_enable=YES   //这里的要添加一行
#

//在客户机上验证的
lftp 192.168.233.9:/pub> ls
-rw-r--r--    1 14       50          65536 Feb 18 16:35 NTUSER.DAT{016888bd-6c6f-11de-8d1d-001e0bcde3ec}.TM.blf
-rw-r--r--    1 0        0               0 Feb 18 16:34 q1
drwxrwxrwx    3 14       50             16 Feb 18 16:30 test0
drwxr-xr-x    2 14       50              6 Feb 18 16:38 test1
drwxr-xr-x    2 14       50              6 Feb 18 16:42 「开始」菜单
lftp 192.168.233.9:/pub> 
lftp 192.168.233.9:/pub> get q1 
lftp 192.168.233.9:/pub> exit
[root@zlb10 ~]# ls
anaconda-ks.cfg  q1
[root@zlb10 ~]# 

在这里插入图片描述
配置虚拟用户FTP

[root@zlb9 ~]# vim /etc/vsftpd/vu.list
[root@zlb9 ~]# cat /etc/vsftpd/vu.list
tom
123
jerry
456
[root@zlb9 ~]# 

[root@zlb9 ~]# db_load -T -t hash -f /etc/vsftpd/vu.list /etc/vsftpd/vu.db   //将文件转换成数据库文件
[root@zlb9 ~]# chmod 600 /etc/vsftpd/vu.*   //提高安全性,避免数据泄露
[root@zlb9 ~]# ll /etc/vsftpd/vu.*
-rw------- 1 root root 12288 Feb 19 04:07 /etc/vsftpd/vu.db
-rw------- 1 root root    18 Feb 19 04:06 /etc/vsftpd/vu.list
[root@zlb9 ~]# 

[root@zlb9 ~]# useradd -d /opt/ftp -s /sbin/nologin vftp   //这里要添加映射账号,创建根目录
[root@zlb9 ~]# ll -d /opt/ftp/
drwx------ 2 vftp vftp 62 Feb 19 04:11 /opt/ftp/
[root@zlb9 ~]# chmod 755 /opt/ftp/
[root@zlb9 ~]# ll -d /opt/ftp/
drwxr-xr-x 2 vftp vftp 62 Feb 19 04:11 /opt/ftp/
[root@zlb9 ~]# 

[root@zlb9 ~]# cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
[root@zlb9 ~]# vim /etc/pam.d/vsftpd   //为虚拟用户建立PAM认证

#%PAM-1.0
auth required pam_userdb.so db=/etc/vsftpd/vu
account required pam_userdb.so db=/etc/vsftpd/vu~ 

[root@zlb9 ~]# vim /etc/vsftpd/vsftpd.conf 

guest_enable=YES
guest_username=vftp    //这上面的2行是添加虚拟用户支持
user_config_dir=/etc/vsftpd/vusers_dir
allow_writeable_chroot=YES   //这2行是为虚拟用户建立独立的配置文件

[root@zlb9 ~]# 
[root@zlb9 ~]# vim /etc/vsftpd/vsftpd.conf 
[root@zlb9 ~]# mkdir /etc/vsftpd/vusers_dir
[root@zlb9 ~]# ll /etc/vsftpd/
total 36
-rw-------. 1 root root   125 Mar 23  2017 ftpusers
-rw-------. 1 root root   361 Mar 23  2017 user_list
-rw-------  1 root root  5135 Feb 19 04:32 vsftpd.conf
-rwxr--r--. 1 root root   338 Mar 23  2017 vsftpd_conf_migrate.sh
-rw-------  1 root root 12288 Feb 19 04:07 vu.db
-rw-------  1 root root    18 Feb 19 04:06 vu.list
drwxr-xr-x  2 root root     6 Feb 19 04:32 vusers_dir
[root@zlb9 ~]# 

[root@zlb9 ~]# cd /etc/vsftpd/vusers_dir/
[root@zlb9 vusers_dir]# vim tom   //设置Tom用户可以上传文件,创建目录
[root@zlb9 vusers_dir]# cat tom 
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
[root@zlb9 vusers_dir]# touch jerry   //但是jerry只要下载权限
[root@zlb9 vusers_dir]# ll
total 4
-rw-r--r-- 1 root root  0 Feb 19 04:36 jerry
-rw-r--r-- 1 root root 79 Feb 19 04:36 tom
[root@zlb9 vusers_dir]# 

此处用的Tom的验证
在这里插入图片描述
在这里插入图片描述
这里是用的Jerry进行验证的
在这里插入图片描述
配置本地用户的FTP

[root@zlb10 ~]# vim /etc/vsftpd/vsftpd.conf 
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO    //只修改此处的,其他地方保持默认
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#

[root@zlb10 ~]# systemctl restart vsftpd
[root@zlb10 ~]# 

[root@zlb10 ~]# useradd qaz
[root@zlb10 ~]# passwd qaz
Changing password for user qaz.
New password: 
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@zlb10 ~]# 
[root@zlb10 ~]# cd /home/qaz/
[root@zlb10 qaz]# ls
[root@zlb10 qaz]# touch q2
[root@zlb10 qaz]# mkdir test3
[root@zlb10 qaz]# ll
total 0
-rw-r--r-- 1 root root 0 Feb 19 06:35 q2
drwxr-xr-x 2 root root 6 Feb 19 06:36 test3
[root@zlb10 qaz]# 

//查看上传下载的文件
[root@zlb10 ~]# cd /home/qaz/
[root@zlb10 qaz]# ll
total 0
drwxr-xr-x 2 qaz  qaz  6 Feb 19 06:42 NetHood
-rw-r--r-- 1 root root 0 Feb 19 06:35 q2
drwxr-xr-x 2 root root 6 Feb 19 06:36 test3
[root@zlb10 qaz]# 

注意:在刚开始做的时候会出现错误,这是因为/etc/pam.d/vsftpd 文件被修改了,可以用备份的回复到原来的配置。这样才不会报错。
在这里插入图片描述在这里插入图片描述在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值