Installation and configuration of vsftpd under linux use detailed steps recommended by of

  • 2020-06-23 02:36:17
  • OfStack

vsftpd, short for very secure FTP daemon, is one of its biggest features.

vsftpd is the name of a server running on an UNIX class operating system. It can run on systems such as Linux, BSD, Solaris, ES13en-ES14en, etc. It is a completely free, open source ftp server software that supports many features that other FTP servers do not support.

Examples: very high security requirements, bandwidth limitations, good scalability, virtual user creation, IPv6 support, high speed.

vsftpd is one of the most admired FTP server programs in the Linux distribution. Feature is compact light, safe and easy to use.

1.1 installation

Command:


yum install vsftpd -y

Configuration Vsftpd

After installation, we need to configure it so that it can be used normally.

Edit the configuration file for vsftpd


 vi /etc/vsftpd/vsftpd.conf

Find "anonymous_enable=YES" in the configuration file and change "YES" to "No" to disable anonymous login.

Add startup automatically,


chkconfig vsftpd on

You can run chkconfig? list to view if you are not sure if a boot entry has been added

1.2 Creating users

Command: useradd ftpuser

Specify password: passwd ftpuser

This user is used to log in to the ftp server.

So once a user is done, you can log in with this, remember to log in with normal instead of anonymous. The default path after login is /home/ftpuser.

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

Set the account of FTP user, for example, the account is "ftpuser1", the directory is /home/ftpuser1, and the setting does not allow login through ssh.


useradd -d /home/ftpuser -s /sbin/nologin ftpuser 

Set the password for your account, such as "ftpuser"


passwd ftpuser

1.3 Enable selinux permission

VSFTPD is an FTP server program, and SELinux is the firewall component of CentOS. Since vsftpd is blocked by default by SELinux, the following problems can be encountered with FTP:

(Transmission completed, but opening path failed)

Failed to change directory (failed to change path)

3.
553 Could not create file.

4.

Or even after sending the LIST command, the server fails to respond and the timeout disconnects.

In such cases, vsftpd usually does not have sufficient permissions and is most likely blocked by SELinux.

View command: getsebool-a | grep ftp


getsebool -a | grep ftpd
# The following permissions are displayed, off It's closing permissions, on It's open permissions 
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

Where ftp_home_dir and allow_ftpd_full_access must be on for vsftpd to have access to the ftp root directory, as well as file transfer and so on.

Setup command: ES151en-ES152en xxxxxx on


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

1.4 Set or close the firewall

Since ftp defaults to port 21 and centos defaults to not being turned on, the iptables file is modified

Settings: vi /etc/sysconfig/iptables

We have 22-ES171en ACCEPT at the top of the line and then we go down to the next line and type the same thing, just replace 22 with 21, and then: wq save.

Again, restart iptables

Restart: service iptables restart

Close the firewall: service iptables stop

Disable firewall restart: chkconfig iptables off

1.5 start vsftpd

Command: service vsftpd start

java client (code) call


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. The connection 
      client.connect(host,port);
      //2. The login 
      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 add date 
    path+=datePath;
    FTPClient client = threadLocal.get();
    String host = threadLocalHost.get();
    //3. Specifies the file upload path ( The path does not return false)
    boolean exists = client.changeWorkingDirectory(path);
    if(!exists) {
      String pathArray[] = path.split("/");
      String temp = "/";
      for(String p:pathArray) {
        temp+=(p+"/");
        //4. If the file path does not exist, it is created (1 Secondary can only create 1 Level directory )
        client.makeDirectory(temp);
      }
      // Re-specify the file upload path 
      client.changeWorkingDirectory(path);
    }
    //5. Specify file type 
    client.setFileType(FTP.BINARY_FILE_TYPE);
    // To obtain the suffix 
    String suffix = fileName.substring(fileName.lastIndexOf("."));
    String uuid = UUID.randomUUID().toString();
    //6. Perform upload 
    client.storeFile(uuid+suffix, local);
    //7. exit 
    client.logout();
    //8. disconnect 
    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");
     // Upload path 
    String res = upload(local, "code.png","/home/ftpuser/ego");
    System.out.println(res);
  }
}

conclusion

Above is the site to introduce linux vsftpd installation and configuration of the use of detailed steps, I hope to help you, if you have any questions welcome to leave a message, the site will promptly reply you!


Related articles: