FTP传输

ftp服务端192.168.1.10
客户端192.168.1.11

匿名用户访问

服务器
[root@localhost ~]# yum -y install ftp vsftpd                          下载所需服务
[root@localhost ~]# chown ftp /var/ftp/pub/
[root@localhost ~]# chmod 777 /var/ftp/pub/
[root@localhost ~]# ll -d /var/ftp/pub/
drwxrwxrwx. 2 ftp root 6 10月 31 2018 /var/ftp/pub/
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf 
在最后添加
anon_upload_enable=YES        允许匿名用户上传文件
anon_mkdir_write_enable=YSE   允许匿名用户有创建和写的权力
[root@localhost ~]# firewall-cmd --permanent --add-service=ftp
success
[root@localhost ~]# firewall-cmd --reload 
success
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl start vsftpd

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              取消注释

客户端
[root@localhost Desktop]# yum -y install ftp vsftpd                下载服务
[root@localhost ~]# ftp 192.168.1.20                               ftp服务器
Connected to 192.168.1.20 (192.168.1.20).
220 (vsFTPd 3.0.2)
Name (192.168.1.20:root): ftp               用户名
331 Please specify the password.
Password:                                   密码
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls                                      查看
227 Entering Passive Mode (192,168,1,20,21,71).
150 Here comes the directory listing.
drwxrwxrwx    2 14       0               6 Oct 30  2018 pub
226 Directory send OK.
ftp> cd pub                                   进入目录
250 Directory successfully changed.
ftp> put initial-setup-ks.cfg                 上传文件
local: initial-setup-ks.cfg remote: initial-setup-ks.cfg
227 Entering Passive Mode (192,168,1,20,254,152).
150 Ok to send data.
226 Transfer complete.
1663 bytes sent in 0.000791 secs (2102.40 Kbytes/sec)
ftp> get root.tar                              下载文件
local: root.tar remote: root.tar
227 Entering Passive Mode (192,168,1,20,99,196).
150 Opening BINARY mode data connection for root.tar (3829760 bytes).
226 Transfer complete.
3829760 bytes received in 0.028 secs (136928.74 Kbytes/sec)
ftp> 

本地用户访问

服务器
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf                修改配置文件
   local_umask=077     实现本机用户登录,匿名仅限于属主用户登录权限
   local_user          去掉注释
最后一行添加:
  allow_writeable_chroot=YES  允许限制的用户主目录拥有写的权限
  userlist_enable =yes
  userlist_deny=NO
[root@localhost ~]# vim /etc/vsftpd/user_list                   修改添加本地用户

# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
sun

[root@localhost ~]# systemctl restart vsftpd                      重新启动

客户端
[root@localhost ~]# ftp 192.168.1.20               ftp服务器
Connected to 192.168.1.20 (192.168.1.20).
220 (vsFTPd 3.0.2)
Name (192.168.1.20:root): sun                       用户名
331 Please specify the password.
Password:                                          输入用户密码
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 
                  在这put上传的文件会放在用户的家目录下

虚拟用户访问

[root@localhost ~]# vim /etc/vsftpd/users.list
首先生成一个用户列表
单行为用户名      双行为密码
szd
123.com
jhl
123.com

db_load -T -t hash -f users.list  users.db       执行这行命令必须在/etc/vsftpd下才能执行
命令字	   -T	-t    加密方式   -f   使用哪个文件创建   创建出的文件叫什么
3.现在我们要修改当前目录中所有以users.开头的文件的权限,将他们的 权限改为600。也就是说我们要让其他用户不能够随便的获取到这个文件中的信息。
chmod   600  users.*
[root@localhost vsftpd]# useradd -s /sbin/nologin -d /sss sss
[root@localhost vsftpd]# chown -R sss:sss /sss/
[root@localhost vsftpd]# vim /etc/pam.d/user.vu   写入下面内容创建支持虚拟用户的PAM认证文件

#%PAM-1.0
auth required pam_userdb.so db=/etc/vsftpd/users
account required pam_userdb.so db=/etc/vsftpd/users
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd.conf                           修改配置文件如下
在其中进行如下的修改:
anonymous_enable=NO
local_enable=YES
并且在文件的最下方,我们添加修改如下的内容
pam_service_name=user.vu
userlist_enable=YES
tcp_wrappers=YES
guest_username=sss
guest_enable=YES
allow_writeable_chroot=YES
anon_world_readable_only=NO
virtual_use_local_privs=NO
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=30100
user_config_dir=/etc/vsftpd/vsftpd_user_conf
客户端
[root@localhost ~]# ftp 192.168.1.20      ftp服务器
Connected to 192.168.1.20 (192.168.1.20).
220 (vsFTPd 3.0.2)
Name (192.168.1.20:root): jhl             输入列表内的用户
331 Please specify the password.
Password:                                 输入列表内的用户密码
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> put initial-setup-ks.cfg             上传到sss目录
local: initial-setup-ks.cfg remote: initial-setup-ks.cfg
227 Entering Passive Mode (192,168,1,20,117,134).
150 Ok to send data.
226 Transfer complete.
1663 bytes sent in 0.000161 secs (10329.19 Kbytes/sec)
ftp> get bin.tar                          下载到本地目录
local: bin.tar remote: bin.tar
227 Entering Passive Mode (192,168,1,20,117,138).
150 Opening BINARY mode data connection for bin.tar (10240 bytes).
226 Transfer complete.
10240 bytes received in 0.000141 secs (72624.11 Kbytes/sec)
ftp> exit

用户名是我们最开始再users.list里编辑的用户名称 ,密码就是对应的密码。

注意!如果我们在开启了服务后又去添加或修改了users.list这个文件的内容
那么我们需要重新生成一个口令库文件并重启服务。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值