Linux搭建ftp服务器简单教程及使用方法
参考文章:https://www.waitig.com/linux-or-centos-install-vsftpd-and-setup-it.html
步骤概括如下:
安装:yum install vsftpd
操作: service vsftpd start|stop|restart
配置部分(重点):
1. 为了系统安全,一般会建立一个ftp用户,此用户不能登陆系统,且只能访问自己主目录下的文件。
useradd -d /var/ftp/test -g ftp -s /sbin/nologin ftpuser
其中,-d命令是指定用户主目录,-g是指定用户分组,-s /sbin/nologin 是禁止用户登陆系统,最后ftpuser是本次新建用户的用户名。
然后设置密码:passwd fptuser
2. 配置用户可登陆名单,并将新建用户添加进入ftp可登陆名单中。
配置用户名单的方式是:打开配置文件,找到如下两行行,去掉其注释符号。
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
这样就定义了一个用户名单,只有名单中的用户可以登陆系统。
3. 创建这个/etc/vsftpd/chroot_list 文件,将可以访问的用户名 ftpuser 添加进去。然后重启ftp服务即可。
操作解释:
-d /var/ftp/test ---------------------------------- 远程机器访问这台ftp服务器的根目录,文件列表与这个目录一致。
useradd/passwd --------------------------------- 本地的用户名和密码
/etc/vsftpd/chroot_list --------------------------- 将本地用户名XX作为ftp用户名
ftp及scp命令的使用
参考文章:http://www.cnblogs.com/weafer/archive/2011/06/13/2079509.html
ftp :
1. ftp 192.168.26.66
2. 输入用户名和密码
3.get 下载
格式:get [remote-file] [local-file]
将文件从远端主机中传送至本地主机中.
注意:文件都下载到了linux主机的当前目录下。比如,在 /root/yint下运行的ftp命令,则文件都下载到了/root/yint 下。
4.put 上传
格式: put local-file [remote-file]
注意:上传文件都来自于主机的当前目录下。比如,在 /root/test下运行的ftp命令,则只有在/root/test下的文件linux才会 上传到服务器e:\rose 下。
scp:
scp是安全的文件拷贝,基于ssh的登录
假定你想把本地计算机/home下的一个名为a.tar.tz的文件拷贝到远程服务器192.168.0.2上的/home/tmp。而且你在远程服务器 上的帐号名为root。可以用这个命令:
scp /home/a.tar.tz root@192.168.0.2:/home/tmp/
----------------------------------------------------------
附录: (参考链接:http://www.linuxsv.org/training/l23_linux_ftp.html)
FTP File Transfer Protocol allows file transfer between hosts on a network without having to login on a standard shell directly on the remote host. The file transfer is done using a standard set of simple commands without encryption, so it must be used only in a not hostile environment. Features like 'scp' that uses ssh protocol for encrypted file transfer can be used to file transfers on a hostile environment like Internet.
FTP Server
In order to configure a host as a FTP server the package vsftp must be installed, configured through /etc/vsftpd/vsftpd.conf and configured to be started at boot.
# yum install vsftpd
# chkconfig vsftpd on
# /etc/init.d/vsftpd start
/etc/vsftpd/vsftpd.conf
This is the main configuration file and specifies the
way that the FTP server runs. The most important parameters that can be
configured are the following :
anonymous_enable=YES
It allows FTP transfer using the anonymous user with password anonymous.
local_enable=YES
Local accounts are valid FTP accounts.
write_enable=YES
Enables write operations on FTP.
#anon_upload_enable=YES
It allows anonymous user to upload files. By default this line is
commented so the anonymous user by default con not upload files to the
FTP server.
#chroot_list_enable=YES
With chroot_local_user=YES you can configure users who are logged
on FTP server to be confined in to their home directory on the FTP
server. Disabled by default.
pam_service_name=vsftpd
Configures Pluggable Authentication Modules (PAM) security for FTP.
userlist_enable=YES
Keeps users such as root and system user listed on
/etc/vsftpd/user_list from logging into the FTP server. It must be
activated always !!!
tcp_wrappers=YES
Supports the use of security commands in /etc/hosts.allow and /etc/hosts.deny through tcpwrappers
FTP Security
Firewall
The FTP server listen on port 21 TCP so it must be open on the firewall .
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
In the case of FTP server is also required to load the nat
iptable module that keep track all FTP connections and allows it. This
configuration is applied on /etc/sysconfig/iptables-config file :
IPTABLES_MODULES="nf_conntrack_ftp"-->/etc/sysconfig/iptables-config
# /etc/init.d/iptables restart
SElinux
There are five directives associated with making FTP server work with SELinux in targeted mode:
# setsebool -P allow_ftpd_full_access 1
If this parameter is enabled ftpd will run on a SElinux context without any restriction.
# setsebool -P allow_ftpd_anon_write 1
Supports the writing of files to directories configured with the public_content_rw_t SELinux setting.
# setsebool -P allow_ftpd_use_cifs 1
Allows the use of files shared via CIFS on an FTP server.
# setsebool -P allow_ftpd_use_nfs 1
Allows the use of files shared via NFS on an FTP server.
# setsebool -P ftp_home_directory 1
Supports FTP read/write access to user home directories.
In addition any directory that is going to be used on read-write
FTP operations it must be labelled as 'public_content_rw_t' SElinux
attribute in order to work correctly in SElinux targered mode .
# chcon -R -t public_content_rw_t /var/pub/ftp
FTP anonymous server
In this section we are going to configure a FTP
server on rhel6 server and only allow anonymous login. Only downloading
data from FTP server must be allowed files, uploading must be forbidden.
# cat /etc/vsftpd/vsftp.conf | grep -v ^#
anonymous_enable=YES
local_enable=NO
write_enable=NO
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
Configure the firewall as defined on 'FTP Security'. If
SElinux is running on targered mode the easy way applied in this case is
give full access to the ftpd daemon on SElinux context :
# setsebool -P allow_ftpd_full_access 1
Lets create a file on the root of the ftp directory /var/ftp/pub. This file will be downloaded by anonymous user.
# dd if=/dev/null of=/var/ftp/pub/file bs=1024 count=1000
And finally restart the ftp service. Make sure the service starts correctly watching logs on /var/log/messages.
# /etc/init.d/vsftpd restart
From another host login to the FTP server on rhel6 as anonymous
user using the FTP client 'lftp'. Download file created previously and
verify that uploading is forbidden.
node01> lftp 192.168.1.10
lftp 192.168.1.10:~> cd pub
cd ok, cwd=/pub
lftp 192.168.1.10:/pub> ls
-rw-r--r-- 1 0 0 10240000 Feb 22 20:36 file
lftp 192.168.1.10:/pub> get file
10240000 bytes transferred
By default the FTP client 'lftp' login as anonymous. From there
file has been downloaded correctly. Lets try to download a file :
lftp 192.168.1.10:/pub> put anaconda-ks.cfg
put: Access failed: 550 Permission denied. (anaconda-ks.cfg)
Uploads are not allowed.
lftp 192.168.1.10:/> cd /var
cd: Access failed: 550 Failed to change directory. (/var)
Navigate outside the FTP server is not allowed.
Try to login as other user as anonymous and verify that only anonymous logins are permitted.
node01> lftp -u john
Password:
lftp john@:~> ls
ls: Not connected
The same is we try as root and other users ... only anonymous logins are allowed.
FTP non-anonymous server
In this case we are going to configure an FTP server
on rhel6 that must only allow logins to all system users less the listed
on /etc/vsftpd/user_list . Download/upload must be allowed for these
users.
cat /etc/vsftpd/vsftpd.conf | grep -v ^#
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
Configure the firewall as defined on 'FTP Security'. In this case we are going to configure ftpd to run on SElinux environment. This is not the easy way as in previous example :
# setsebool -P allow_ftpd_full_access 0
# setsebool -P allow_ftpd_anon_write 1
# setsebool -P allow_ftpd_use_cifs 1
# setsebool -P allow_ftpd_use_nfs 1
# setsebool -P ftp_home_dir 1
Lets create a file on 'john' /home dir of the ftp directory /home/john. This file will be downloaded by user john.
# cp /var/ftp/pub/file /home/john
# chown john:john /home/john/file
And finally restart the ftp service. Make sure the service starts correctly watching logs on /var/log/messages.
# /etc/init.d/vsftpd restart
From another host login to the FTP server on rhel6 as 'john'
user using the FTP client 'lftp'. Download file created previously and
verify that uploading is allowed on john /home.
node01> lftp -u john 192.168.1.10
Password:
lftp john@192.168.1.10:~> ls
-rw-r--r-- 1 1001 1001 10240000 Feb 22 22:08 file
lftp john@192.168.1.10:~> get file
10240000 bytes transferred
lftp john@192.168.1.10:~> put install.log
21820 bytes transferred
lftp john@192.168.1.10:~> ls
-rw-r--r-- 1 1001 1001 10240000 Feb 22 22:08 file
-rw-r--r-- 1 1001 1001 21820 Feb 23 20:06 install.log
lftp john@192.168.1.10:~> cd /var
lftp john@192.168.1.10:/var>
As can be seen 'john' user can download/upload files on
/home/john through FTP. But 'john' still has access to directories
outside his home, on Lab1 we will configure the FTP server to chroot users onto his home directory.
Users listed on /etc/vsftpd/user_list are not allowed to login on FTP server :
node01> lftp -u root 192.168.1.10
Password:
lftp root@192.168.1.10:~> dir
`ls' at 0 [Delaying before reconnect: 20]
...
FTP Client
As has been seen in previous sections the lftp RPM can be used as FTP Client.
# yum install lftp
In order to login as user 'john' on FTP server 192.168.1.10 :
lftp -u john 192.168.1.10
Password:
lftp john@192.168.1.10:~>
If no user is specified the FTP login is done using the anonymous user.
In order to execute a remote command on the FTP server as 'ls' :
lftp john@192.168.1.10:~> ls
-rw-r--r-- 1 1001 1001 10240000 Feb 22 22:08 file
-rw-r--r-- 1 1001 1001 21820 Feb 23 20:06 install.log
In order to execute a local command on the FTP client as 'ls' :
lftp john@192.168.1.10:~> ! ls
file install.log install.log.syslog test
To download a file from FTP server use 'get' command :
lftp john@192.168.1.10:~> get file
10240000 bytes transferred
To upload a file from FTP client to the FTP server use 'put' command :
lftp john@192.168.1.10:~> put install.log
21820 bytes transferred
More info on 'man lftp'.
Questions
1.- By default FTP data transfer is encrypted (true/false).
2.- FTP protocol can be used to transfer files between Linux, Unix and Microsoft Windows S.O. (true/false).
3.- In order to get working an FTP server through a firewall the only action required is open 21/TCP port (true/false).
4.- Which configuration parameter on file
/etc/vsftpd/vsftpd.conf must be configured in order to allow anonymous
login on the FTP server?.
5.- Which configuration parameter on file
/etc/vsftpd/vsftpd.conf must be configured in order disable local logins
on the FTP server?.
6.- Which configuration parameter on file
/etc/vsftpd/vsftpd.conf must be configured in order disable logins from
users listed in /etc/vsftpd/vsftpd.conf on the FTP server?.
7.- Which command can be used in order to disable SElinux protection to the ftpd service?.
8.- Which command can be used in order to give
SElinux access to users logged through FTP client on their home
directories on the FTP server?.
9.- Which command can be used in order to connect to the FTP server using anonymous account?.
A - lftp 192.168.1.10
B - lftp -u anonymous 192.168.1.10
C - Both of them
D - None of them
10.- Which configuration parameter on
/etc/vsftpd/vsftpd.conf makes that the only users listed on
/etc/vsftpd/user_list are allowed to connect to the FTP server ?.
A - userlist_deny=YES
B - userlist_deny=NO
C - /etc/export
D - /etc/fstab
Linux搭建ftp服务器简单教程及使用方法的更多相关文章
- 使用Linux搭建FTP服务器实现文件共享
使用Linux搭建FTP服务器实现文件共享... ---------------- Linux中的文件共享:FTPVSFTPDVSFTPD虚拟用户 FTP可以用在Linux与Linux 和Window ...
- Linux启动ftp服务器530 Permission denied解决方法(已试,行)
Linux启动ftp服务器530 Permission denied解决方法重新在虚拟机下安装了linux.现在我想启动linux自带的ftp服务器:#service vsftpd start . ...
- Linux 搭建FTP服务器
介绍 本章主要介绍在Linux中搭建FTP服务器的过程,需要掌握的要点是配置文件的合理配置. 知识点 在linux中使用的FTP是vsftp FTP可以有三种登入方式分别是: 匿名登录方式:不需要用户 ...
- Linux搭建SVN服务器详细教程
前言 本文讲解Linux系统下如何搭建SVN服务器,详细说明各配置项的功能,最终实现可管控多个项目的复杂配置. SVN是subversion的缩写,是一个开放源代码的版本控制系统,通过采用分支管理系统 ...
- centos6.3搭建FTP服务器图文教程
今天下午不忙,没什么事,看到我大红盟linux版块如此冷清,心不能忍,做了个FTP服务器的搭建教程,大家可以看看, 不会做视频,就图文交叉了,写得不好,望谅解.以后有时间再出一个LNMP的教程. 不磨 ...
- Linux搭建FTP服务器
一.搭建环境 阿里云 CentOS 7.3 64位 二.FTP协议基础知识 2.1 简介 FTP 是 File Transfer Protocol(文件传输协议)的英文简称,而中文简称为"文 ...
- Linux搭建FTP服务器实战
首先准备一台Linux系统机器(虚拟机也可), 检测出是否安装了vsftpd软件: rpm -qa |grep vsftpd 如果没有输出结果,就是没有安装. 使用命令安装,安装过程中会有提示,直接输 ...
- linux搭建FTP服务器并整合Nginx
操作系统:Centos7 1.1.服务器配置 # 关闭SELINUX,把SELINUX=enforcing改为SELINUX=disabled,reboot重启服务器生效 vim /etc/sysco ...
- Linux篇---ftp服务器的搭建
一.前述 企业中linux搭建ftp服务器还是很实用的,所以本文针对centoos7和centoos6搭建服务器教程做个总结. 二.具体 1.显示如下图则表示已安装 vsftp软件.如果未显示则需要安 ...
随机推荐
- 如何在国内跑Kubernetes的minikube
跑minikube start老是被卡住,得到如以下的结果 minikube start --registry-mirror=https://registry.docker-cn.com miniku ...
- 卸载CUDA和cuDNN
卸载CUDA和cuDNN 1.卸载CUDA 本教程只针对对于.run方式安装的,其他的没有进行测试 打开终端,输入sudo /usr/local/cuda-10.0/bin/uninstall_cud ...
- ubuntu下python3.6.5import tensorflow显示非法指令(核心已转储)
1.版本 ubuntu版本为14.04 python为3.6.5 tensorflow为pip3安装的1.8.0版本 2.解决 删除原先的tensorflow:sudo pip3 uninstall ...
- 热门前沿知识相关面试问题-MVC/MVP/MVVM架构设计模式面试问题详解
MVC[最常用]: MVC的定义:M:业务逻辑处理.[业务MODEL]V:处理数据显示的部分.[如xml布局文件]C:Activity处理用户交互的问题.[也就是Activity在MVC中扮演着C的角 ...
- PHP工程师学习计划
从开始学习PHP到现在,只是大致的对PHP的一些基础的东西了解一下,从没有制定一个较为完整的学习计划,所以自己的编程水平一直都处在基本的入门阶段,所以结合自己的实际情况制定了一个感觉还算合理的学习计划 ...
- 王道机试指南题解(C/C++版)
第 2 章 经典入门 一 排序 例 2.1 排序 代码 2.1 冒泡排序(时间复杂度 \(O(n^2)\)) #include <iostream> using std::cin; usi ...
- 02-SQLServer数据库附加后处于只读模式
一.总结 附加数据库后,遇到只读,并且取消只读的时候报错操作系统错误,一般都是附加的时候,使用的是SQLServer用户登录附加的,只要使用windows用户登录数据库重新附加一下就ok了. 二.处理 ...
- BZOJ 1818: [Cqoi2010]内部白点 (BIT + 扫描线)
就是求多条线段的交点数,直接BIT+扫描线就行了. 注意不要算重最初存在的点. CODE #include<bits/stdc++.h> using namespace std; char ...
- 通过远程 HTTP GET 请求载入信息
jQuery.get(url, [data], [callback], [type]) 概述 通过远程 HTTP GET 请求载入信息. 这是一个简单的 GET 请求功能以取代复杂 $.ajax .请 ...
- MessagePack Java Jackson Dataformat 在 Map 中不使用 String 为 Key 的序列化
当你希望在 Map 中不使用 String 为 Key,那么你需要使用 MessagePackKeySerializer 来为 key 进行序列化. 本测试方法,可以在 https://github. ...