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.
Open the vsftpd configuration file:
sudo nano /etc/vsftpd.confAdd the following line to specify a new directory for all FTP users:
local_root=/var/ftpEnsure the specified directory exists:
sudo mkdir -p /var/ftp sudo chown ftpuser:ftpuser /var/ftpRestart 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.
Open the vsftpd configuration:
sudo nano /etc/vsftpd.confAdd or modify the following lines:
chroot_local_user=YES allow_writeable_chroot=YESEnsure 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 usedRestart 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.
Set
local_rootfor individual users by editing/etc/vsftpd.confor using user-specific configuration files.For user-specific configuration:
Create a directory for user config files:
sudo mkdir -p /etc/vsftpd_user_confCreate a config file for the user (
ftpuserin this example):sudo nano /etc/vsftpd_user_conf/ftpuserAdd the following content:
local_root=/var/ftp
Update the main vsftpd configuration to enable user-specific configurations:
user_config_dir=/etc/vsftpd_user_confRestart 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
755permissions 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_rootsetting. - 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!
댓글
댓글 쓰기