Linux 部署ftp服务

这篇具有很好参考价值的文章主要介绍了Linux 部署ftp服务。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

文件传输协议(file Transfer Protocol,FTP),它工作在应用层,由客户端软件和服务端软件两个部分共同实现文件传输功能,使用 TCP 传输而不是 UDP, 客户在和服务器建立连接前要经过一个“三次握手”的过程, 保证客户与服务器之间的连接是可靠的, 而且是面向连接,为数据传输提供可靠保证。

ftp 主要使用20和21端口

20端口传输数据;21端口建立连接

主动模式: 服务器主动连接客户端传输
被动模式: 服务器等待客户端连接。


部署ftp服务器

1.查看是否安装过vsftp,没有就下载vsftp

[root@ansible_nfs ~]# rpm -q vsftpd
未安装软件包 vsftpd 
[root@ansible_nfs ~]# yum install -y vsftpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.cqu.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-29.el7_9 将被 安装
--> 解决依赖关系完成

2.查看vsftp软件的详细信息

[root@ansible_nfs 7-3]# rpm -qi vsftpd
Name        : vsftpd
Version     : 3.0.2
Release     : 29.el7_9
Architecture: x86_64
Install Date: 2023年07月07日 星期五 11时42分23秒
Group       : System Environment/Daemons
Size        : 361349
License     : GPLv2 with exceptions
Signature   : RSA/SHA256, 2021年06月11日 星期五 23时06分15秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : vsftpd-3.0.2-29.el7_9.src.rpm
Build Date  : 2021年06月10日 星期四 00时15分50秒
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : https://security.appspot.com/vsftpd.html
Summary     : Very Secure Ftp Daemon
Description :
vsftpd is a Very Secure FTP daemon. It was written completely from
scratch.

3.启动vsftp服务

[root@ansible_nfs 7-3]# service vsftpd start
Redirecting to /bin/systemctl start vsftpd.service

vsftpd — Very Secure FTP Daemon

4.判断ftp服务是否启动

查看vsftpd进程

[root@ansible_nfs 7-3]# ps aux|grep vsftpd
root       1808  0.0  0.0  53292   576 ?        Ss   11:44   0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root       1810  0.0  0.0 112824   984 pts/0    S+   11:44   0:00 grep --color=auto vsftpd

查看vsftpd端口

[root@ansible_nfs 7-3]# netstat -anplut|grep vsftpd
tcp6       0      0 :::21                   :::*                    LISTEN      1808/vsftpd  

查看vsftpd服务状态

[root@ansible_nfs ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 五 2023-07-07 11:44:10 CST; 58min ago
 Main PID: 1808 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─1808 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

7月 07 11:44:10 ansible_nfs systemd[1]: Starting Vsftpd ftp daemon...
7月 07 11:44:10 ansible_nfs systemd[1]: Started Vsftpd ftp daemon.

5.登录ftp服务
  下载客户端工具 ftp和lftp

[root@ansible_nfs 7-3]# yum install ftp lftp -y

默认情况下不允许root用户登录

[root@ansible_nfs vsftpd]# lftp 192.168.2.24
lftp 192.168.2.24:~> ls
中断                           
lftp 192.168.2.24:~> exit

6.新建用户sc测试ftp服务

[root@ansible_nfs 7-3]# useradd sc
[root@ansible_nfs 7-3]# id sc
uid=1042(sc) gid=1042(sc) 组=1042(sc)
[root@ansible_nfs 7-3]# echo "12345"|passwd sc --stdin
更改用户 sc 的密码 。
passwd:所有的身份验证令牌已经成功更新。

7.登录lftp:格式:lftp -u 用户名、密码 ip地址

[root@ansible_nfs ~]# lftp -u sc,12345 192.168.2.24
lftp sc@192.168.2.24:~> ls
lftp sc@192.168.2.24:/> pwd     
ftp://sc:12345@192.168.2.24/
lftp sc@192.168.2.24:/> mkdir sanchuang
mkdir 成功, 建立 `sanchuang'
lftp sc@192.168.2.24:/> ls
drwx------    2 1042     1042            6 Jul 07 05:28 sanchuang

8.查看lftp常用命令

lftp sc@192.168.2.24:/> help
    !<shell-command>                     (commands)                           alias [<name> [<value>]]             attach [PID]                         bookmark [SUBCMD]
    cache [SUBCMD]                       cat [-b] <files>                     cd <rdir>                            chmod [OPTS] mode file...            close [-a]
    [re]cls [opts] [path/][pattern]      debug [<level>|off] [-o <file>]      du [options] <dirs>                  exit [<code>|bg]                     get [OPTS] <rfile> [-o <lfile>]
    glob [OPTS] <cmd> <args>             help [<cmd>]                         history -w file|-r file|-c|-l [cnt]  jobs [-v] [<job_no...>]              kill all|<job_no>                    lcd <ldir>
    lftp [OPTS] <site>                   ln [-s] <file1> <file2>              ls [<args>]                          mget [OPTS] <files>                  mirror [OPTS] [remote [local]]
    mkdir [-p] <dirs>                    module name [args]                   more <files>                         mput [OPTS] <files>                  mrm <files>
    mv <file1> <file2>                   [re]nlist [<args>]                   open [OPTS] <site>                   pget [OPTS] <rfile> [-o <lfile>]     put [OPTS] <lfile> [-o <rfile>]      pwd [-p]
    queue [OPTS] [<cmd>]                 quote <cmd>                          repeat [OPTS] [delay] [command]      rm [-r] [-f] <files>                 rmdir [-f] <dirs>
    scache [<session_no>]                set [OPT] [<var> [<val>]]            site <site-cmd>                      source <file>                        torrent [-O <dir>] <file|URL>...
    user <user|URL> [<pass>]             wait [<jobno>]                       zcat <files>                         zmore <files>
lftp sc@192.168.2.24:/>
lcd命令 : 在本地切换目录
!ls : 查看本地目录内容
lftp sc@192.168.2.24:/> lcd /tmp
lcd 成功, 本地目录=/tmp
lftp sc@192.168.2.24:/> !ls
crontab.3jDKSH								 vmware-root_680-2689143817  vmware-root_687-4022112208  vmware-root_696-2722173465
file1									 vmware-root_683-4013919829  vmware-root_688-2688750615  vmware-root_698-2730496923
memlog_{mem_monitor.sh}.log						 vmware-root_684-2697598348  vmware-root_690-2697074069  vmware-root_701-3979708482
systemd-private-18d619f418854e2b9704e239e455cbe2-chronyd.service-SycrL7  vmware-root_685-4013788754  vmware-root_692-2696942994
systemd-private-3a8e0357f3fc4688834d7b8bed6eefe5-chronyd.service-CCZNvw  vmware-root_686-2689274894  vmware-root_694-2688619536

put命令 上传文件到ftp服务器
lftp sc@192.168.2.24:/> put memlog_{mem_monitor.sh}.log 
180 bytes transferred                                         
lftp sc@192.168.2.24:/> ls
-rw-------    1 1042     1042         1241 Jul 07 05:32 anaconda-ks.cfg
-rw-r--r--    1 1042     1042          180 Jul 07 06:48 memlog_{mem_monitor.sh}.log
drwx------    2 1042     1042            6 Jul 07 05:28 sanchuang
lftp sc@192.168.2.24:/> rm -rf anaconda-ks.cfg 
rm 成功, 删除 `anaconda-ks.cfg'
lftp sc@192.168.2.24:/> ls
-rw-r--r--    1 1042     1042          180 Jul 07 06:48 memlog_{mem_monitor.sh}.log
drwx------    2 1042     1042            6 Jul 07 05:28 sanchuang

mirror命令 下载文件夹到本地
lftp sc@192.168.2.24:/> lcd 
lcd 成功, 本地目录=/root
lftp sc@192.168.2.24:/> mirror sanchuang/
Total: 1 directory, 0 files, 0 symlinks
lftp sc@192.168.2.24:/> !ls
anaconda-ks.cfg    sanchuang

9.进行备份ftp服务的主要配置文件

[root@ansible_nfs vsftpd]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf

[root@ansible_nfs /]# cd /etc/vsftpd/
[root@ansible_nfs vsftpd]# cp vsftpd.conf vsftpd.conf.bak


一、匿名用户

1.修改配置文件,vim /etc/vsftpd/vsftpd.conf

anon_upload_enable=YES            #允许匿名用户上传文件,取消注释
anon_mkdir_write_enable=YES     #允许匿名用户创建目录,需取消注释
anon_other_write_enable=YES      #允许匿名删除、重命名、覆盖等操作,需添加
 
anon_root=/var/ftp/pub       
#anon_root 针对匿名用户(如果不设置默认为此目录,可以进行修改,修改之后修改给它权限)

anonymous_enable=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  	  #设置用户所上传数据的权限掩码
#
# 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  #允许匿名删除、重命名、覆盖等操作(新增)

anon_root=/var/ftp/pub       
#anon_root 针对匿名用户(如果不设置默认为此目录,可以进行修改,修改之后修改给它权限)

2.修改文件 /var/ftp/pub 权限为777

            -R : 对目前目录下的所有档案与子目录进行相同的权限变更(即以递回的方式逐个变更)

[root@ansible_nfs pub]# pwd
/var/ftp/pub
[root@ansible_nfs ftp]# ll
总用量 0
drwxr-xr-x 2 root root 6 6月  10 2021 pub
[root@ansible_nfs ftp]# chmod -R 777 /var/ftp/pub/
[root@ansible_nfs ftp]# ll
总用量 0
drwxrwxrwx 2 root root 6 6月  10 2021 pub

 3.重启vsftpd服务

[root@ansible_nfs vsftpd]# systemctl restart vsftpd

4.windows匿名访问测试

首先确保Linux和windows是同一网段,Linux虚拟机网络可以选择为桥接模式,并且都需要关闭防火墙。

windows的ip地址

linux搭建ftp服务器,Linux笔记,linux,网络,服务器

Linux里ip地址

[root@ansible_nfs vsftpd]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:cc:31:b9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.24/24 brd 192.168.2.255 scope global noprefixroute dynamic ens33
       valid_lft 80909sec preferred_lft 80909sec
    inet6 fe80::20c:29ff:fecc:31b9/64 scope link 
       valid_lft forever preferred_lft forever

Linux里关闭防火墙和selinux

[root@ansible_nfs vsftpd]# vim vsftpd.conf
[root@ansible_nfs vsftpd]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@ansible_nfs vsftpd]# getenforce
Disabled

windows里关闭防火墙

linux搭建ftp服务器,Linux笔记,linux,网络,服务器


win+r 进入cmd;ftp  ftp服务器ip地址

linux搭建ftp服务器,Linux笔记,linux,网络,服务器

或者用之前创建的用户sc登录

 linux搭建ftp服务器,Linux笔记,linux,网络,服务器

  在FTP服务器中的共享目录中创建一个文件 ,在windows里查看是否可查看文件

[root@ansible_nfs vsftpd]# cd /var/ftp/pub
[root@ansible_nfs vsftpd]# mkdir sanchuang.txt run.sh
[root@ansible_nfs pub]# ls
sanchuang.txt   run.sh

linux搭建ftp服务器,Linux笔记,linux,网络,服务器

可以将文件下载到windows里并查看

linux搭建ftp服务器,Linux笔记,linux,网络,服务器

在windows中创建文件上传后去ftp服务器查看
在windows桌面创建文本changsha.txt  
使用 put changsha.txt 上传

linux搭建ftp服务器,Linux笔记,linux,网络,服务器

linux搭建ftp服务器,Linux笔记,linux,网络,服务器

 [root@ansible_nfs pub]# ls
changsha.txt  run.sh  sanchuang.txt


二、用户登录

1.修改配置文件vsftpd.conf

anonymous_enable=NO           #关闭匿名用户访问

local_umask=077                       #修改为077

新增3行
chroot_local_user=YES            #将访问禁锢在用户的宿主目录中
allow_writeable_chroot=YES    #允许被限制的用户主目录具有写权限
local_root=/var/www/data          #上传默认位置  可以更改及注释
 
#anon_mkdir_write_enable=YES  注释    
#anon_other_write_enable=YES  注释

[root@ansible_nfs vsftpd]# vim vsftpd.conf

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=077  	   #可设置仅宿主用户拥有被上传的文件的权限为077
#
# 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   #注释

chroot_local_user=YES  			#将访问禁锢在用户的宿主目录中
allow_writeable_chroot=YES 		#允许被限制的用户主目录具有写权限
local_root=/var/www/data 		#上传默认位置  可以更改及注释

重启vsftpd服务
[root@ansible_nfs vsftpd]# systemctl restart vsftpd
[root@ansible_nfs vsftpd]# 

2.创建一个目录作为FTP的共享目录,创建一个用户,把此目录作为此用户的属主目录

[root@ansible_nfs vsftpd]# cd /var/ftp/
[root@ansible_nfs vsftpd]# mkdir data
[root@ansible_nfs ftp]# ls
data  pub
[root@ansible_nfs ftp]# useradd yy
[root@ansible_nfs ftp]# echo 123|passwd yy --stdin
更改用户 yy 的密码 。
passwd:所有的身份验证令牌已经成功更新。

递归更改属主
[root@ansible_nfs ftp]# chown -R yy:root data
[root@ansible_nfs ftp]# ll
总用量 0
drwxr-xr-x 2 yy   root  6 7月   7 13:04 data
drwxrwxrwx 2 root root 61 7月   7 16:34 pub

3.创建文件并且授予权限,然后重启服务

[root@ansible_nfs www]# mkdir -p /var/www/data/
[root@ansible_nfs www]# chmod 777 /var/www/data/
[root@ansible_nfs www]# ll
总用量 0
drwxrwxrwx 4 root root 82 7月   7 16:14 data
[root@ansible_nfs www]# systemctl restart vsftpd

4.在windows浏览器里直接输入 ftp://192.168.2.24(需要输入用户和密码)

linux搭建ftp服务器,Linux笔记,linux,网络,服务器

linux搭建ftp服务器,Linux笔记,linux,网络,服务器

linux搭建ftp服务器,Linux笔记,linux,网络,服务器文章来源地址https://www.toymoban.com/news/detail-718214.html

到了这里,关于Linux 部署ftp服务的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • LINUX通过vsftpd搭建FTP服务器 ( 最快 最直接的方式)

    这里只说最快最直接的方式,至于后面的权限配置,我就不写了。百度一大把 这里只记录成功将文件从MACBOOK通过FTP传到UBUNTU的过程 1.安装vsftpd sudo apt install vsftpd 2.查看服务状态,启动,停止等 systemctl status|start|stop vsftpd.service 基于systemctl的单元服务操作,不多说,都懂 3.Vstp配

    2024年02月10日
    浏览(40)
  • Linux中搭建FTP服务器,匿名用户访问、本地用户访问、虚拟用户访问(详细解答安装配置步骤)

    对于Linux搭建服务器步骤详解:可以基于匿名访问、本地用户访问、虚拟用户访问 FTP服务访问可分为三种 匿名用户:用户名为ftp或者anonymous,提供任意密码或无密码访问即可. 本地用户:要求有用户名和相对应密码,适用于使用者都是使用此服务器的人。 虚拟用户(出于安全

    2024年02月10日
    浏览(60)
  • 【Linux】主机搭建 Linux服务器环境 笔记

    过年买了个 mini 主机当玩具玩一下,这里记录下。 已有主力机 (windows) 的情况下,使用过如下四种 Linux宿主环境。这里总结下区别。 优点 云服务器 虚拟机 笔记本电脑 mini主机 价格低 √ √ 便携 √ √ 环境隔离 √ √ √ 详细过程不贴出来了,把关键点回忆一下,方便以后快

    2024年02月21日
    浏览(51)
  • 【Linux】FTP文件服务器

    FTP (File transfer protocol) 是TCP/IP 协议组中的协议之一。他最主要的功能是在服务器与客户端之间进行文件的传输。FTP就是实现两台计算机之间的拷贝,从远程计算机拷贝文件至自己的计算机上,称之为“下载 (download)”文件。将文件从自己计算机中拷贝至远程计算机上,则称

    2024年02月10日
    浏览(50)
  • 自建服务器系列-0元搭建linux服务器(windows笔记本)

    下载地址 准备一个32G以上的U盘 工具: ultraISO :下载地址 1、打开UltraISO工具,左上角点击文件选项-打开,选择下载好的iso镜像,如下: 2、点击工具栏启动选项-写入磁盘映像…-如下图弹窗中点击写入 3.等待刻录完成即可。 我的这台机器是dell inspiron 14 cpu: i7 4774 内存:8G (

    2024年04月25日
    浏览(36)
  • FTP服务器移植到Linux开发板

    提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 提示:这里可以添加本文要记录的大概内容: 将Linux开发板作为一个小型的 FTP 服务器,这样就可以通过 FileZilla 软件直接在开发板和 windows 之间通过网络进行文件互传。在开发板上搭建 FTP 服务器很简单

    2024年02月14日
    浏览(37)
  • Linux高并发服务器开发---笔记1(环境搭建、系统编程、多进程)

    0613 首先这整个系列笔记属于笔记①:牛客校招冲刺集训营—C++工程师中的 第四章 笔记。 视频课链接: 视频1:Linux高并发服务器开发(40h); 视频2:第4章 项目制作与技能提升(录播)(26h30min); 视频课3: 第5章 高频考点与真题精讲(录播)中的 5.10-5.13 项目回顾 有个学

    2024年02月15日
    浏览(50)
  • 驱动程序开发:FTP服务器和OpenSSH的移植与搭建、以及一些笔记

      将 ALPHA 开发板作为一个小型的 FTP 服务器,这样我们就可以通过 FileZilla 软件直接在开发板和 windows 之间通过网络进行文件互传。而在开发板上搭建 FTP 服务器很简单,就是 vsftpd 的移植。   FileZilla官网下载,下载地址如下:点击链接。步骤省略。   现在需要在自己

    2024年02月09日
    浏览(38)
  • Linux 配置FTP服务器 + vsftpd服务安装配置 (Good篇)

    VSFTPD 实现客户端和服务器之间传输文件 目录 什么是VSFTPD? VSFTPD 的特点和功能 1. 设置和使用FTP服务器的步骤 1. 下载vsftpd包 2. 启动服务 开机自启 3. 关闭防火墙 4. 配置vsftpd服务    常用 配置选项 匿名用户 本地用户 设置进入提示 2.重启vsftpd服务(重点) 3进入 /var/ftp ftp根目

    2024年02月02日
    浏览(42)
  • Windows访问Linux下的FTP服务器(Centos和Uuntu)

    1.下载FTP离线安装包: http: / /rpmfind .net/linux/rpm2html/search .php?query=vsftpd (x86-64 )    选择最后一个 vsftpd-3.0.2-28.el7.x86_64.rpm 2.检查是否已经安装了vsftp rpm -qa | grep vsftpd 出现提示vsftpd版本号则表示已安装,没有则未安装 3.安装vsftpd(推荐离线) 离线安装 rpm -ivh vsftpd-3.0.2-22.el7.x86_

    2024年02月09日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包