Centos7--FTP

[root@localhost ~]# yum -y install vsftpd  //安装ftp服务器
[root@localhost ~]# yum -y install ftp   //安装ftp客户端
[root@localhost ~]# systemctl enable vsftpd
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# cd /var/ftp/pub/
[root@localhost pub]# echo this is a file for download > download.txt  // 测试匿名用户下载功能

匿名用户访问FTP服务器

 

默认情况下FTP服务器仅允许匿名用户从服务器下载文件,而不允许匿名用户上传文件到服务器以及在服务器上创建目录

[root@localhost pub]# vim /etc/vsftpd/vsftpd.conf
anon_mkdir_write_enable=YES   //允许匿名用户在FTP上创建目录
anon_upload_enable=YES  //允许匿名用户在FTP服务器上上传文件
anon_other_write_enable=YES  //开启匿名用户的其他写权限
[root@localhost pub]# mkdir /var/ftp/upload
[root@localhost pub]# chmod 777 /var/ftp/upload
[root@localhost pub]# systemctl restart vsftpd

普通用户访问FTP服务器

 

普通用户的FTP主目录为其在虚拟机上的家目录(/home/user1),默认在该目录下拥有完全权限,可以上传文件创建文件并改名

使用命令访问FTP服务器

C:\Users\12806>ftp 192.168.16.130  //登录到FTP服务器
连接到 192.168.16.130。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
用户(192.168.16.130:(none)): ftp  //用户名为FTP表示匿名用户(windo系统默认的匿名用户为:anonymous)
331 Please specify the password.
密码:  //匿名用户不需要密码
230 Login successful.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
pub
upload
226 Directory send OK.
ftp: 收到 16 字节,用时 0.00秒 16.00千字节/秒。
ftp> cd  pub
250 Directory successfully changed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
download.txt
226 Directory send OK.
ftp: 收到 17 字节,用时 0.00秒 17.00千字节/秒。
ftp> ? //查看所有命令 ?+ 命令可以查看命令的作用
命令可能是缩写的。  命令为:

!               delete          literal         prompt          send
?               debug           ls              put             status
append          dir             mdelete         pwd             trace
ascii           disconnect      mdir            quit            type
bell            get             mget            quote           user
binary          glob            mkdir           recv            verbose
bye             hash            mls             remotehelp
cd              help            mput            rename
close           lcd             open            rmdir
ftp> dir  //查看当前目录下所有文件
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r--    1 0        0              28 May 09 10:20 download.txt
226 Directory send OK.
ftp: 收到 73 字节,用时 0.00秒 73.00千字节/秒。
ftp> get download.txt d:/a.txt  将download.txt文件下载到d:/并且改名为a.txt

锁定普通用户主目录

匿名用户被锁定在其主目录,而普通用户不被锁定在其家目录,可以切换到其他目录中

[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
chroot_list_enable=YES  //启用锁定用户列表文件
chroot_local_user=YES  //将本地普通用户锁定在其主目录下,如果同时启用了chroot_list文件,则该文件中的用户将变为不被锁定的用户
chroot_list_file=/etc/vsftpd/chroot_list  //指定锁定用户列表文件为/etc/vsftpd/chroot_list
allow_writeable_chroot=YES
[root@localhost ~]# systemctl restart vsftpd
[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# vim chroot_list
user1  //想要被锁定的用户user1

控制用户对FTP服务器的服务

[root@localhost vsftpd]# ls
chroot_list  ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh
[root@localhost vsftpd]# vim vsftpd.conf 
userlist_enable=YES  //默认该文件中的用户不能访问FTP服务器
userlist_deny=NO  //不再禁止user_list文件中的用户登录FTP服务器,而不在该文件的用户将默认被禁止
(root用户除外,root用户在ftpusers文件中,无论配置文件怎么修改,该文件中的用户都会被禁止登录)
[root@localhost vsftpd]# vim user_list
user1 //禁止user1用户登录FTP服务器

控制主机对FTP服务器的访问

[root@localhost vsftpd]# vim vsftpd.conf
tcp_wrappers=YES
[root@localhost vsftpd]# ll /etc/hosts.*
-rw-r--r--. 1 root root 370 6月   7 2013 /etc/hosts.allow
-rw-r--r--. 1 root root 460 6月   7 2013 /etc/hosts.deny
[root@localhost vsftpd]# vim /etc/hosts.deny
vsftpd:all  //禁止所有主机访问vsftp服务
[root@localhost vsftpd]# vim /etc/hosts.allow
vsftp:192.168.10.10  //192.168.10.10为真实机VMnet8网卡IP地址
tcp_wrappers会先检查hosts.allow文件
如果在该文件中被允许,即允许访问,不会再检查hosts.deny
如果在该文件中没有匹配的规则,则会检查hosts.deny文件
如果在hosts.deny中被拒绝,则拒绝该主机访问
如果在hosts.deny中也没有相匹配的规则,会允许该主机访问

FTP虚拟目录功能

[root@localhost vsftpd]# cd /var/ftp
[root@localhost ftp]# mkdir share
[root@localhost ftp]# mkdir /software
[root@localhost ftp]# chmod 777 /software/
将真实目录/software挂载到虚拟目录share,以后对FTP匿名用户主目录下share目录的访问其实是对/software目录访问
[root@localhost ftp]# mount --bind /software/ share/
正常情况下FTP匿名用户是访问不到/software的,通过虚拟目录share,匿名用户能够在该目录下拥有完全权限
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值