


Introduction to the installation and configuration of vsftpd under Linux
本文主要介绍了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
配置Vsftpd
安装完之后我们要对它进行配置,才能正常使用。
编辑vsftpd的配置文件
vi /etc/vsftpd/vsftpd.conf
在配置文件中找到“anonymous_enable=YES”,将"YES"改为"No",将匿名登录禁用。
添加开机自动启动,
chkconfig vsftpd on
不确定是否已经加入了开机启动项可以运行chkconfig –list进行查看
1.2 创建用户
命令:useradd ftpuser
指定密码:passwd ftpuser
此用户就是用来登录ftp服务器用的。
这样一个用户建完,可以用这个登录,记得用普通登录不要用匿名了。登录后默认的路径为 /home/ftpuser.
----------------------------------------------------------------------------------------------------------------------------------
设置FTP用户的账号,例如账号为“ftpuser1”,目录为/home/ftpuser1,且设置不允许通过ssh登录。
useradd -d /home/ftpuser -s /sbin/nologin ftpuser
设置账号对应的密码,例如密码为“ftpuser”
passwd ftpuser
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
其中,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
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); } }
相关推荐:
Linux vsftpd连接报错:500 OOPS: 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





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)

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.

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.

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.

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

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.

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.

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.
