linux ftp 服务配置

简介:

1 FTP服务搭建环境

server端:

CentOS release 6.8 (Final)

ip 192.168.91.3

hostname:Darren

client端:

CentOS release 6.6 (Final)

ip 192.168.91.5

hostname:zhishutang

2 server端安装vsftpd服务

[root@Darren ~]# yum -y install vsftpd   

[root@Darren packages]# rpm -qa vsftpd

vsftpd-2.2.2-21.el6.x86_64  

[root@Darren ~]# chkconfig --level 2345 vsftpd on

[root@Darren ~]# /etc/init.d/vsftpd restart

#ftp服务默认为21端口

[root@Darren ~]# netstat -nltup |grep vsftp       

tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      20334/vsftpd  

    

[root@Darren ~]# ps -ef |grep vsftp

root      20334      1  0 12:42 ?        00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

3 client端安装ftp客户端

[root@Darren packages]# yum -y install ftp

[root@zhishutang ~]# rpm -qa ftp

ftp-0.17-54.el6.x86_64

4 常用命令解析

[root@Darren home]# useradd user3    --在server端创建一个测试用户user3

[root@zhishutang ~]# ftp   --在client端登陆

ftp> open 192.168.91.3    --用open指定server端IP地址

Connected to 192.168.91.3 (192.168.91.3).

220 (vsFTPd 2.2.2)

Name (192.168.91.3:root): user3    --输入用户名

331 Please specify the password.

Password:                                      --输入密码

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> help                                       --查看帮助,显示所有ftp命令

Commands may be abbreviated.  Commands are:

!               debug           mdir            sendport        site

$               dir             mget            put             size

account         disconnect      mkdir           pwd             status

append          exit            mls             quit            struct

ascii           form            mode            quote           system

bell            get             modtime         recv            sunique

binary          glob            mput            reget           tenex

bye             hash            newer           rstatus         tick

case            help            nmap            rhelp           trace

cd              idle            nlist           rename          type

cdup            image           ntrans          reset           user

chmod           lcd             open            restart         umask

close           ls              prompt          rmdir           verbose

cr              macdef          passive         runique         ?

delete          mdelete         proxy           send

ftp> close  --断开客户端和服务端ftp连接,不退出ftp的shell

500 OOPS: vsf_sysutil_recv_peek: no data

ftp> disconnect   --同close功能相同

221 Goodbye.

ftp> open 192.168.91.3 21  --指定IP地址和端口,如果为默认端口21,可不指定

ftp> bye    --断开客户端和服务端ftp连接,并退出ftp的shell(功能同quit和!)

500 OOPS: vsf_sysutil_recv_peek: no data

帮助命令:? help  rhelp

ftp> ascii       

200 Switching to ASCII mode.

ftp> binary

200 Switching to Binary mode.

切换响铃以在每个文件传送命令完成后响铃。默认情况下,铃声是关闭的。

ftp> bell

Bell mode on.

ftp> bell

Bell mode off.

ftp> cd /tmp  --切换远程服务端目录

250 Directory successfully changed.

ftp> cdup   --跳到上一层目录

250 Directory successfully changed.

ftp> pwd    --显示远程服务端的目录

257 "/"

ftp> lcd /tmp   --指定更改的本地计算机上的目录

Local directory now /tmp

ftp>ls       --显示远程服务端目录文件和子目录

ftp> dir     --显示远程服务端目录文件和子目录

ftp> size /tmp/root.txt   --显示远程服务端文件的大小12922KB

213 12922

ftp> mkdir /tmp/ftpdir   --创建远程服务端文目录

257 "/tmp/ftpdir" created

ftp> rmdir /tmp/ftpdir   --删除远程服务端文目录

250 Remove directory operation successful.

ftp> rename /tmp/file /tmp/fileuser3    --修改远程服务端文件名

350 Ready for RNTO.

250 Rename successful.

ftp> chmod 755 /tmp/fileuser3   --修改远程服务端文件权限

200 SITE CHMOD command ok.

ftp> modtime fileuser3   --显示远程服务器上的文件的最后修改时间

fileuser3       11/15/2016 08:12:21 GMT

ftp> append /home/file /tmp/file    --将本地文件上传到远程计算机上的文件

local: /home/file remote: /tmp/file

227 Entering Passive Mode (192,168,91,3,113,93).

150 Ok to send data.

226 Transfer complete.

ftp> send /home/file /tmp/file        --将本地文件上传到远程计算机上的文件

local: /home/file remote: /tmp/file

227 Entering Passive Mode (192,168,91,3,99,109).

150 Ok to send data.

226 Transfer complete.

ftp> put /home/file /tmp/file     --将本地文件上传到远程计算机上的文件

local: /home/file remote: /tmp/file

227 Entering Passive Mode (192,168,91,3,56,26).

150 Ok to send data.

226 Transfer complete.

local: /tmp/file remote: /tmp/file   ----将远程计算机上的文件 下载到本地文件

227 Entering Passive Mode (192,168,91,3,62,156).

150 Opening BINARY mode data connection for /tmp/file (0 bytes).

226 Transfer complete.

ftp> recv /tmp/file /tmp/file      ----将远程计算机上的文件下载到本地文件

local: /tmp/file remote: /tmp/file

227 Entering Passive Mode (192,168,91,3,139,114).

150 Opening BINARY mode data connection for /tmp/file (0 bytes).

226 Transfer complete.

ftp> delete /tmp/file    --删除远程计算机上的文件

250 Delete operation successful.

ftp> umask    

200 Your current UMASK is 022

ftp>prompt  --切换交谈式指令(使用mput/mget 时不用每个文件皆询问yes/no)

命令太多,不一一演示。

5 ftp配置文件说明

/etc/vsftpd/ ftpusers    --这个文件中的用户默认不能登录ftp

/etc/vsftpd/user_list     --如果在配置文件/etc/vsftpd/vsftpd.conf中userlist_deny=YES (默认),这个文件/etc/vsftpd/user_list中的          用户不能登录FTP,如果userlist_deny=NO,这个文件/etc/vsftpd/user_list中的用户能登录FTP,

                                        

/etc/vsftpd/vsftpd.conf   --主要配置文件

例如:默认情况root是不能登录FTP的,这里修改配置文件,使root用户可用

[root@Darren vsftpd]# vim /etc/vsftpd/ftpusers

#root  --注释root用户

[root@Darren vsftpd]# vim /etc/vsftpd/user_list

#root  --注释root用户

6 主要配置文件 /etc/vsftpd/vsftpd.conf  

由于这个文件比较重要,这里单独分析

#################本地用户权限控制###############

# 允许本地用户登录

 local_enable=YES

 # 本地用户的写权限

 write_enable=YES

 # 使用FTP的本地文件权限,默认为077

 # 一般设置为022

 local_umask=022

 # 切换目录时

 # 是否显示目录下.message的内容

 dirmessage_enable=YES

 dirlist_enable = NO

 #验证方式

 #pam_service_name=vsftpd

 # 启用FTP数据端口的数据连接

 connect_from_port_20=YES

 # 以独立的FTP服务运行

 listen=yes

 # 修改连接端口

 #listen_port=2121

######### 匿名登录设置 ###########

 # 允许匿名登录

 anonymous_enable=NO

 # 如果允许匿名登录

 # 是否开启匿名上传权限

 #anon_upload_enable=YES

 # 如果允许匿名登录

 # 是否允许匿名建立文件夹并在文件夹内上传文件

 #anon_mkdir_write_enable=YES

 # 如果允许匿名登录

 # 匿名帐号可以有删除的权限

 #anon_other_write_enable=yes

 # 如果允许匿名登录

 # 匿名的下载权限

 # 匿名为Other,可设置目录/文件属性控制

 #anon_world_readable_only=no

 # 如果允许匿名登录

 # 限制匿名用户传输速率,单位bite

 #anon_max_rate=30000

 ######### 用户限制设置 ###########

 #### 限制登录

 # 用userlist来限制用户访问

 #userlist_enable=yes

 # 名单中的人不允许访问

 #userlist_deny=no

 # 限制名单文件放置的路径

 #userlist_file=/etc/vsftpd/userlist_deny.chroot

 #### 限制目录

 # 限制所有用户都在家目录

 #chroot_local_user=yes

 # 调用限制在家目录的用户名单

 chroot_list_enable=YES

 # 限制在家目录的用户名单所在路径

 chroot_list_file=/etc/vsftpd/chroot_list

 ######### 日志设置 ###########

 # 日志文件路径设置

 xferlog_file=/var/log/vsftpd.log

 # 激活上传/下载的日志

 xferlog_enable=YES

 # 使用标准的日志格式

 #xferlog_std_format=YES

 ######### 安全设置 ###########

 # 用户空闲超时,单位秒

 #idle_session_timeout=600

 # 数据连接空闲超时,单位秒

 #data_connection_timeout=120

 # 将客户端空闲1分钟后断开

 #accept_timeout=60

 # 中断1分钟后重新连接

 #connect_timeout=60

 # 本地用户传输速率,单位bite

 #local_max_rate=50000

 # FTP的最大连接数

 #max_clients=200

 # 每IP的最大连接数

 #max_per_ip=5

 ######### 被动模式设置 ###########

 # 是否开户被动模式

 pasv_enable=yes

 # 被动模式最小端口

 pasv_min_port=5000

 # 被动模式最大端口

 pasv_max_port=6000

 ######### 其他设置 ###########

 # 欢迎信息

 ftpd_banner=Welcome to Ftp Server!

7 配置匿名FTP


修改配置文件:

[root@Darren ftp]# vim /etc/vsftpd/vsftpd.conf

anonymous_enable=YES

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_root=/var/ftp/

其他参数默认不变

ftp是系统用户:

[root@Darren vsftpd]# cat /etc/passwd|grep ftp

ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

[root@zhishutang ~]# ftp

ftp> open 192.168.91.3

Connected to 192.168.91.3 (192.168.91.3).

220 (vsFTPd 2.2.2)

Name (192.168.91.3:root): ftp      --使用ftp用户

331 Please specify the password.

Password:          --无密码,直接回车即可

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> pwd

257 "/"  

ftp> ls

227 Entering Passive Mode (192,168,91,3,203,117).

150 Here comes the directory listing.

drwxr-xr-x    2 0        0            4096 Nov 15 10:38 anon

-rw-r--r--    1 14       0               0 Nov 15 11:36 file1

-rw-r--r--    1 0        0               0 Nov 15 11:47 file2

drwxr-xr-x    2 14       0            4096 May 11  2016 pub

226 Directory send OK.

ftp> get /file1 /tmp/file1    --下载文件file1

local: /tmp/file1 remote: /file1

227 Entering Passive Mode (192,168,91,3,196,32).

150 Opening BINARY mode data connection for /file1 (0 bytes).

226 Transfer complete.



本文转自 Darren_Chen 51CTO博客,原文链接:http://blog.51cto.com/darrenmemos/1873414,如需转载请自行联系原作者

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
11天前
|
安全 Ubuntu Java
Linux配置使用篇
Linux配置使用篇
|
23天前
|
存储 负载均衡 索引
linux7安装elasticsearch-7.4.0集群配置
linux7安装elasticsearch-7.4.0集群配置
109 0
|
28天前
|
监控 Linux Shell
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
38 0
|
28天前
|
网络协议 Shell Linux
【Shell 命令集合 网络通讯 】Linux 设置和配置PPP pppsetup命令 使用教程
【Shell 命令集合 网络通讯 】Linux 设置和配置PPP pppsetup命令 使用教程
36 0
|
28天前
|
存储 Shell Linux
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
30 1
|
10天前
|
网络协议 Linux
在Linux中,管理和配置网络接口
在Linux中管理网络接口涉及多个命令,如`ifconfig`(在新版本中被`ip`取代)、`ip`(用于网络设备配置)、`nmcli`(NetworkManager的CLI工具)、`nmtui`(文本界面配置)、`route/ip route`(处理路由表)、`netstat/ss`(显示网络状态)和`hostnamectl/systemctl`(主机名和服务管理)。这些命令帮助用户启动接口、设置IP地址、查看连接和路由信息。不同发行版可能有差异,建议参考相应文档。
19 4
|
3天前
|
存储 关系型数据库 MySQL
Linux服务详解
Linux服务详解
17 0
|
4天前
|
网络协议 Ubuntu Linux
Linux 下 TFTP 服务搭建及 U-Boot 中使用 tftp 命令实现文件下载
Linux 下 TFTP 服务搭建及 U-Boot 中使用 tftp 命令实现文件下载
|
11天前
|
监控 Java Linux
linux下监控java进程 实现自动重启服务
linux下监控java进程 实现自动重启服务
|
13天前
|
Ubuntu 网络安全 数据安全/隐私保护
ubuntu篇-配置FTP服务,本机和docker安装
通过以上步骤,你可以在Ubuntu上配置FTP服务,无论是本机安装还是Docker内安装,都可以提供FTP文件传输服务。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
20 1