FTP file transfer in Linux environment (with experiment diagram)

FTP file transfer experiment

■FTP service-protocol used to transfer files

■FTP server uses TCP protocol port 20 and 21 to communicate with the client by default

  • Port 20 is used to establish a data connection and transfer file data

  • Port 21 is used to establish a control connection and transmit FTP control commands
    ■FTP data connection is divided into active mode and passive mode

  • Active mode: the server actively initiates a data connection

  • Passive mode: The server passively waits for a data connection

1. Install FTP and backup files

yum install -y vsftpd
cd /etc/vsftpd/
cp vsftpd.conf vsftpd.conf.bak

Insert picture description here
Insert picture description here

2. Set up the FTP service accessed by anonymous users (maximum permissions)

#修改配置文件
vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES            #开启匿名用户访问。默认已开启
write_enable=YES                #开放服务器的写权限(若要上传,必须开启)。默认已开启
anon_umask=022                  #设置匿名用户所上传数据的权限掩码(反掩码)。默认已开启
anon_upload_enable=YES          #允许匿名用户上传文件。默认已注释,需取消注释
anon_mkdir_write_enable=YES     #允许匿名用户创建(上传)目录。默认已注释,需取消注释
anon_other_write_enable =YES    #允许删除、重命名、覆盖等操作。需添加

#为匿名访问ftp的根目录下的 pub子目录设置最大权限,以便匿名用户上传数据
chmod 777 /var/ftp/pub/

#开启服务,关闭防火墙和增强型安全功能
systemctl start vsftpd
systemctl stop firewalld
setenforce 0

Insert picture description here

Insert picture description here

3. Anonymous access test

在Windows系统打开 开始 菜单,输入 cmd 命令打开命令提示符
#建立ftp连接
ftp 192.168.163.20
#匿名访问,用户名为ftp,密码为空,直接回车即可完成登录
ftp> pwd			#匿名访问ftp的根目录为Linux系统的/var/ftp/目录
ftp> ls				#查看当前目录
ftp> cd pub			#切换到pub 目录
ftp> get 文件名		#下载文件到当前Windows本地目录
ftp> put 文件名		#上传文件到ftp目录
ftp> quit			#退出

Insert picture description here
Let's switch to Linux to see if there is this file
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

4. Set up local user authentication to access ftp, and prohibit switching to directories other than ftp (the root directory of the default login is the home directory of the local user)

#修改配置文件
vim /etc/vsftpd/vsftpd.conf
local_enable=Yes        		 #启用本地用户
anonymous_enable=NO     		 #关闭匿名用户访问
write_enable=YES        		 #开放服务器的写权限(若要上传,必须开启)
anon_umask=077          		 #可设置仅宿主用户拥有被上传的文件的权限(反掩码)
chroot_local_user=YES   		 #将访问禁锢在用户的宿主目录中
allow_writeable_chroot=YES		 #允许被限制的用户主目录具有写权限

重启服务
systemctl restart vsftpd

ftp 192.168.80.10
或
ftp://[email protected]
修改匿名用户、本地用户登录的默认根目录(这个在配置文件里填上即可,这就不演示了)
anon_root=/var/www/html			#anon_root 针对匿名用户
local_root=/var/www/html		#local_root 针对系统用户

使用user_list 用户列表文件
vim /etc/vsftpd/user_list
//末尾添加zhangsan用户
zhangsan

vim /etc/vsftpd/vsftpd.conf
userlist_enable=YES    #启用user_list用户列表文件
userlist_deny=NO       #设置白名单,仅对user_list用户列表文件的用户访问。默认为YES,为黑名单,禁用

Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/zhangyuebk/article/details/113971104
Recommended