vsftpd default directory

The default directory for FTP users in vsftpd depends on how the FTP server is configured and the user’s home directory setup. Below are different configurations and their impact on the default directory that users are placed in when they connect to the server.


1. Default Directory Behavior with vsftpd

  • When a user logs in via FTP, they are typically placed in their home directory.
  • By default, the home directory is located at /home/<username>, where <username> is the name of the FTP user.

For example:

  • If the FTP user is ftpuser, the default login directory will be /home/ftpuser/.

2. Changing the Default Directory for Users

A. Using local_root Configuration

You can specify a custom directory (other than the user’s home directory) for FTP users by setting the local_root parameter in the vsftpd configuration file.

  1. Open the vsftpd configuration file:

    sudo nano /etc/vsftpd.conf
    
  2. Add the following line to specify a new directory for all FTP users:

    local_root=/var/ftp
    
  3. Ensure the specified directory exists:

    sudo mkdir -p /var/ftp
    sudo chown ftpuser:ftpuser /var/ftp
    
  4. Restart the vsftpd service:

    sudo systemctl restart vsftpd
    

This will set /var/ftp as the default directory for all FTP users (unless overridden by other settings).


B. Using chroot_local_user to Restrict Users

If you want to restrict users to their home directories, you can use the chroot_local_user option.

  1. Open the vsftpd configuration:

    sudo nano /etc/vsftpd.conf
    
  2. Add or modify the following lines:

    chroot_local_user=YES
    allow_writeable_chroot=YES
    
  3. Ensure the user’s home directory exists and is accessible:

    sudo mkdir -p /home/ftpuser
    sudo chown ftpuser:ftpuser /home/ftpuser
    sudo chmod a-w /home/ftpuser  # vsftpd requires the home directory to not be writable if chroot is used
    
  4. Restart the vsftpd service:

    sudo systemctl restart vsftpd
    

This configuration will restrict each user to their home directory.


C. Allowing FTP Users Access to a Shared Directory

If you want multiple FTP users to share a common directory (like /var/ftp), you can change their default directory to the shared directory.

  1. Set local_root for individual users by editing /etc/vsftpd.conf or using user-specific configuration files.

  2. For user-specific configuration:

    • Create a directory for user config files:

      sudo mkdir -p /etc/vsftpd_user_conf
      
    • Create a config file for the user (ftpuser in this example):

      sudo nano /etc/vsftpd_user_conf/ftpuser
      
    • Add the following content:

      local_root=/var/ftp
      
  3. Update the main vsftpd configuration to enable user-specific configurations:

    user_config_dir=/etc/vsftpd_user_conf
    
  4. Restart vsftpd:

    sudo systemctl restart vsftpd
    

Now, the user ftpuser will be directed to /var/ftp upon login.


3. Permissions and Ownership Considerations

Make sure the FTP user has appropriate permissions for the default directory. Example:

sudo chown ftpuser:ftpuser /var/ftp
sudo chmod 755 /var/ftp
  • 755 permissions ensure the user can read, write, and access the directory.
  • If using chroot, the directory must not be writable (chmod a-w) for security reasons.

4. Verifying the FTP Default Directory

To confirm which directory the user logs into, check the FTP session logs:

sudo tail -f /var/log/vsftpd.log

You can also test the FTP connection using:

ftp <ftp-server-ip>

Summary

  • By default, FTP users are directed to their home directories (e.g., /home/ftpuser).
  • You can change the default directory for all users or specific users using the local_root setting.
  • Use chroot if you want to restrict users to their default directory.
  • Ensure permissions are correctly set on the target directory.

Let me know if you encounter any issues!

댓글

이 블로그의 인기 게시물

Using the MinIO API via curl

How to split a list into chunks of 100 items in JavaScript, 자바스크립트 리스트 쪼개기

HTML Inline divisions at one row by Tailwind

Boilerplate for typescript server programing

가속도 & 속도

Gradle multi-module project

How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

CDPEvents in puppeteer

Sparse encoder

Reactjs datetime range picker