ftp

ftp

1.匿名用户登录

1.1 安装vsftp
[root@zhangruilin ~]# yum -y install vsftp
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com

1.2 开启vsftpd服务
[root@zhangruilin ~]# systemctl start vsftpd
[root@zhangruilin ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 一 2019-11-04 18:13:34 CST; 11s ago
  Process: 4567 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 4568 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─4568 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

11月 04 18:13:34 zhangruilin systemd[1]: Starting Vsftpd ftp daemon...
11月 04 18:13:34 zhangruilin systemd[1]: Started Vsftpd ftp daemon.

1.3 编辑/etc/vsftpd/vsftpd.conf文件将anon_upload_enable=YES注释取消掉
[root@zhangruilin ~]# vim /etc/vsftpd/vsftpd.conf
[root@zhangruilin ~]# grep  -C1 'anon_upload_enable=YES' /etc/vsftpd/vsftpd.conf
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
anon_upload_enable=YES
#
[root@zhangruilin ~]# systemctl restart vsftpd
1.4 将/var/ftp/pub目录的权限设置为可读写执行权限
[root@zhangruilin ~]# setfacl -m u:ftp:rwx /var/ftp/pub

1.5 然后就可以匿名登录并且上传目录了

在这里插入图片描述

1.6然后编辑文件/etc/vsftpd/vsftpd.conf文件将anon_mkdir_write_enable=YES注释取消掉
[root@zhangruilin pub]# grep -C1 'anon_mkdir_write' /etc/vsftpd/vsftpd.conf
# new directories.
anon_mkdir_write_enable=YES
#

1.7然后就可以创建目录了

在这里插入图片描述

2.系统用户登录只能在指定目录里上传或者下载

1.创建用户tom
[root@zhangruilin ~]# useradd tom
[root@zhangruilin ~]# id tom
uid=1107(tom) gid=1110(tom) 组=1110(tom)
2.给tom设置密码
[root@zhangruilin ~]# echo '123456' |passwd --stdin tom
更改用户 tom 的密码 。
passwd:所有的身份验证令牌已经成功更新。

3.创建目录,并给系统用户tom权限
[root@zhangruilin ~]# mkdir /opt/runtime
[root@zhangruilin ~]# setfacl -m u:tom:rwx /opt/runtime
3.编辑/etc/vsftpd/vsftpd.conf配置文件,将系统用户登录的家目录设置为刚创建的目录/opt/runtime,并开启禁锢所有的ftp本地用户于其家目录中,然后再写入allow_writeable_chroot=YES意思是允许被禁锢的用户家目录有写权限
[root@zhangruilin ~]# vim /etc/vsftpd/vsftpd.conf
[root@zhangruilin ~]# grep  -B1 '^chroot' /etc/vsftpd/vsftpd.conf
local_root=/opt/runtime
chroot_local_user=YES
allow_writeable_chroot=YES
4.重启vsftpd服务
[root@zhangruilin ~]# systemctl restart vsftpd
5.然后用xfstp登录验证发现用户只能在其指定目录下上传下载

在这里插入图片描述

6.在另一台客户端上登录验证是否可以创建
[root@localhost ~]# ftp 192.168.100.128
Connected to 192.168.100.128 (192.168.100.128).
220 (vsFTPd 3.0.2)
Name (192.168.100.128:root): tom
331 Please specify the password.
Password:
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
ftp> mkdir a
257 "/a" created
ftp> ls
227 Entering Passive Mode (192,168,100,128,171,235).
150 Here comes the directory listing.
-rw-r--r--    1 1111     1114          835 Nov 05 01:58 1.txt
drwxr-xr-x    2 1111     1114            6 Nov 05 02:14 a
226 Directory send OK.

7.在服务器上的/opt/runtime里就能看到上传的目录了
[root@zhangruilin ~]# ll /opt/runtime
总用量 4
-rw-r--r--. 1 tom tom 835 11月  5 09:58 1.txt
drwxr-xr-x. 2 tom tom   6 11月  5 10:14 a

3.虚拟用户

3.1 在/etc/vsftpd/vu.list写上虚拟用户tom和jerry的密码
[root@zhangruilin ~]# cat >/etc/vsftpd/vu.list<<EOF
> tom
> 123
> jerry
> 456
> EOF
[root@zhangruilin ~]# cd /etc/vsftpd
[root@zhangruilin vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh  vu.list
[root@zhangruilin vsftpd]# cat vu.list
tom
123
jerry
456
3.2 安装libdb-utils
`[root@zhangruilin vsftpd]# yum -y install libdb-utils
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 libdb-utils.x86_64.0.5.3.21-20.el7 将被 升级
---> 软件包 libdb-utils.x86_64.0.5.3.21-25.el7 将被 更新
--> 正在处理依赖关系 libdb(x86-64) = 5.3.21-25.el7,它被软件包 libdb-utils-5.3.21-25.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libdb.x86_64.0.5.3.21-20.el7 将被 升级
---> 软件包 libdb.x86_64.0.5.3.21-25.el7 将被 更新
--> 解决依赖关系完成


3.3 将刚创建的文本格式用户名、密码文件使用db4工具转换成数据库文件并将权限设置为600
[root@zhangruilin vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh  vu.list
[root@zhangruilin vsftpd]# db_load -T -t hash -f vu.list vu.db
[root@zhangruilin vsftpd]# ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh  vu.db  vu.list
[root@zhangruilin vsftpd]# chmod 600 vu*
[root@zhangruilin vsftpd]# ll
总用量 36
-rw-------. 1 root root   125 3月  23 2017 ftpusers
-rw-------. 1 root root   361 3月  23 2017 user_list
drwxr-xr-x. 2 root root    30 11月  6 11:44 v_config
-rw-------. 1 root root  5132 11月  6 11:42 vsftpd.conf
-rwxr--r--. 1 root root   338 3月  23 2017 vsftpd_conf_migrate.sh
-rw-------. 1 root root 12288 11月  6 11:36 vu.db
-rw-------. 1 root root    18 11月  6 11:34 vu.list

3.4 添加虚拟用户的映射帐号、创建ftp根目录,并修改权限为755
[root@zhangruilin vsftpd]# useradd -d /opt/haha -s /sbin/nologin vftp
[root@zhangruilin vsftpd]# ll /opt
drwx------. 2 vftp vftp 62 11月  6 11:37 haha
[root@zhangruilin vsftpd]# chmod 755 /opt/haha
[root@zhangruilin vsftpd]# ll /opt
drwxr-xr-x. 2 vftp vftp 62 11月  6 11:37 haha
3.5 为虚拟用户建立PAM认证,
[root@zhangruilin vsftpd]# cd /etc/pam.d
[root@zhangruilin pam.d]# mv vsftpd{,-bak}
[root@zhangruilin pam.d]# ls vsftpd-bak
vsftpd-bak
[root@zhangruilin pam.d]# cat >vsftpd<<EOF
> #%PAM-1.0
> auth required pam_userdb.so db=/etc/vsftpd/vu
> account required pam_userdb.so db=/etc/vsftpd/vu
> EOF
[root@zhangruilin pam.d]# cat vsftpd
#%PAM-1.0
auth required pam_userdb.so db=/etc/vsftpd/vu
account required pam_userdb.so db=/etc/vsftpd/vu

3.6 创建目录,并修改vsftpd配置文件,添加虚拟用户支持
[root@zhangruilin vsftpd]# mkdir v_config
[root@zhangruilin vsftpd]# tail -4 /etc/vsftpd/vsftpd.conf
guest_enable=YES
guest_username=vftp
user_config_dir=/etc/vsftpd/v_config
allow_writeable_chroot=YES

3.7 创建tom,jerry目录,并为不同的虚拟用户建立独立的配置文件,然后重启服务
[root@zhangruilin v_config]# touch tom
[root@zhangruilin v_config]# touch jerry
[root@zhangruilin v_config]# ls
jerry  tom
[root@zhangruilin v_config]# vim tom
[root@zhangruilin v_config]# cat tom
anon_upload_enable=YES
anon_mkdir_write_enable=YES
[root@zhangruilin v_config]# cat jerry
[root@zhangruilin v_config]# systemctl restart vsftpd

3.8 验证tom可以创建文件,上传和下载,而jerry只能进去看文件

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

3.9客户端验证,tom可以创建目录并且在服务器的vftp的家目录/opt/haha
Connected to 192.168.100.128 (192.168.100.128).
220 (vsFTPd 3.0.2)
Name (192.168.100.128:root): tom
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> mkdir a
257 "/a" created
ftp> ls
227 Entering Passive Mode (192,168,100,128,23,180).
150 Here comes the directory listing.
drwx------    2 1111     1114            6 Nov 06 04:37 a
226 Directory send OK.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值