Home Operation and Maintenance Linux Operation and Maintenance Introduction to the installation and configuration of vsftpd under Linux

Introduction to the installation and configuration of vsftpd under Linux

Jan 09, 2018 am 09:52 AM
linux vsftpd introduce

本文主要介绍了linux下vsftpd的安装及配置使用详细步骤 ,需要的朋友可以参考下,希望能帮助到大家。

vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点。

vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux、BSD、Solaris、 HP-UNIX等系统上面,是一个完全免费的、开放源代码的ftp服务器软件,支持很多其他的 FTP 服务器所不支持的特征。

比如:非常高的安全性需求、带宽限制、良好的可伸缩性、可创建虚拟用户、支持IPv6、速率高等。

vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序。特点是小巧轻快,安全易用。

1.1  安装

命令:

yum install vsftpd -y
Copy after login

配置Vsftpd

安装完之后我们要对它进行配置,才能正常使用。

编辑vsftpd的配置文件

 vi /etc/vsftpd/vsftpd.conf
Copy after login

在配置文件中找到“anonymous_enable=YES”,将"YES"改为"No",将匿名登录禁用。

添加开机自动启动,

chkconfig vsftpd on
Copy after login

不确定是否已经加入了开机启动项可以运行chkconfig –list进行查看

1.2  创建用户

命令:useradd ftpuser

指定密码:passwd ftpuser

此用户就是用来登录ftp服务器用的。

这样一个用户建完,可以用这个登录,记得用普通登录不要用匿名了。登录后默认的路径为 /home/ftpuser.

----------------------------------------------------------------------------------------------------------------------------------

设置FTP用户的账号,例如账号为“ftpuser1”,目录为/home/ftpuser1,且设置不允许通过ssh登录。

useradd -d /home/ftpuser -s /sbin/nologin ftpuser
Copy after login

设置账号对应的密码,例如密码为“ftpuser”

passwd ftpuser
Copy after login

1.3  开启selinux权限

VSFTPD是一个FTP服务器程序,然后SELinux是CentOS的防火墙组件。由于 vsftpd 默认被 SELinux 拦截,所以会遇到的FTP以下的问题:

1.226 Transfer done (but failed to open directory).(传输完成,但是打开路径失败)

2.550 Failed to change directory(更改路径失败)

3.
553 Could not create file.

4.

或者干脆在发送了LIST命令以后,服务器没响应,超时断开。

遇到这样的问题,通常是vsftpd 没有足够的权限,很有可能是被SELinux阻止了。

查看命令:getsebool -a | grep ftp

getsebool -a | grep ftpd
#以下是显示出来的权限,off是关闭权限,on是打开权限
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftpd_connect_db --> off
ftpd_use_passive_mode --> off
ftp_home_dir --> off
Copy after login

其中,ftp_home_dir和allow_ftpd_full_access必须为on 才能使vsftpd 具有访问ftp根目录,以及文件传输等权限。

      设置命令:setsebool -p xxxxxx on

[root@bogon ~]# setsebool -P allow_ftpd_full_access on
[root@bogon ~]# setsebool -P ftp_home_dir on
Copy after login

1.4  设置或关闭防火墙

因为ftp默认的端口为21,而centos默认是没有开启的,所以要修改iptables文件

设置:vi /etc/sysconfig/iptables

在行上面有22 -j ACCEPT 下面另起一行输入跟那行差不多的,只是把22换成21,然后:wq保存。

还要运行下,重启iptables

重启:service iptables restart

关闭防火墙:service iptables stop

禁用防火墙重启:chkconfig iptables off

1.5  启动vsftpd

命令:service vsftpd start

  java客户端(代码)调用

package com.jonychen.util;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.util.Date;
import java.util.UUID;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
public class FtpUploadUtil {
  private static ThreadLocal<FTPClient> threadLocal = new ThreadLocal<>();
  private static ThreadLocal<String> threadLocalHost = new ThreadLocal<>();
  public static void init(String host,int port,String username,String password) throws SocketException, IOException {
    FTPClient client = threadLocal.get();
    if(client==null) {
      client = new FTPClient();
      //1.连接
      client.connect(host,port);
      //2.登录
      client.login(username,password);
      threadLocal.set(client);
      threadLocalHost.set(host);
    }
  }
  public static String upload(InputStream local,String fileName,String path) throws SocketException, IOException {
    String datePath = DateUtil.date2Str(new Date(),"/yyyy/MM/dd/");
    //路径添加日期
    path+=datePath;
    FTPClient client = threadLocal.get();
    String host = threadLocalHost.get();
    //3.指定文件上传路径(路径不存在返回false)
    boolean exists = client.changeWorkingDirectory(path);
    if(!exists) {
      String pathArray[] = path.split("/");
      String temp = "/";
      for(String p:pathArray) {
        temp+=(p+"/");
        //4.如果文件路径不存在,则创建(一次只能创建一级目录)
        client.makeDirectory(temp);
      }
      //重新指定文件上传路径
      client.changeWorkingDirectory(path);
    }
    //5.指定文件类型
    client.setFileType(FTP.BINARY_FILE_TYPE);
    //获取后缀
    String suffix = fileName.substring(fileName.lastIndexOf("."));
    String uuid = UUID.randomUUID().toString();
    //6.执行上传
    client.storeFile(uuid+suffix, local);
    //7.退出
    client.logout();
    //8.断开连接
    client.disconnect();
    threadLocalHost.remove();
    threadLocal.remove();
    return "http://"+host+"/jonychen"+datePath+uuid+suffix;
  }
  public static void main(String[] args) throws SocketException, IOException {
    InputStream local = new FileInputStream("D:\\Documents\\Pictures\\01.png");
    init("192.168.178.161", 21, "ftpuser", "111111");
     //上传路径
    String res = upload(local, "code.png","/home/ftpuser/ego");
    System.out.println(res);
  }
}
Copy after login

相关推荐:

Linux vsftpd连接报错:500 OOPS: vsftpd的解决办法详解

Linux下利用MySQL建立VSFTPD下的虚拟用户

vsftpd+MySQL创建虚拟用户在Debian Linux之下

The above is the detailed content of Introduction to the installation and configuration of vsftpd under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

See all articles