Ftp server #linux #services

 To enable and use an FTP server on Kali Linux, you can use `vsftpd` (Very Secure FTP Daemon). Here’s a step-by-step guide:


### 1. Install vsftpd

First, install `vsftpd` using the following command:

```bash

sudo apt update

sudo apt install vsftpd

```


### 2. Configure vsftpd

After installation, you need to configure the FTP server. The configuration file is located at `/etc/vsftpd.conf`.


Open the configuration file with a text editor:

```bash

sudo nano /etc/vsftpd.conf

```


### 3. Basic Configuration

Make the following changes to the configuration file for a basic setup:


- Uncomment the following lines:

  ```plaintext

  write_enable=YES

  local_umask=022

  ```

  

- Add or modify the following lines to ensure proper functionality:

  ```plaintext

  anonymous_enable=NO

  local_enable=YES

  chroot_local_user=YES

  ```


### 4. Create FTP Directory and Set Permissions

Create a directory for the FTP users and set the appropriate permissions. For example, you can create a directory called `ftp` under `/home`:

```bash

sudo mkdir /home/ftp

sudo chmod 755 /home/ftp

```


### 5. Create an FTP User

Create a user for FTP access. Replace `ftpuser` with the desired username:

```bash

sudo adduser ftpuser

```

Follow the prompts to set the password and user details.


### 6. Start vsftpd Service

Start the `vsftpd` service and enable it to start on boot:

```bash

sudo systemctl start vsftpd

sudo systemctl enable vsftpd

```


### 7. Adjust Firewall Settings

If you have a firewall enabled, allow FTP traffic:

```bash

sudo ufw allow 20/tcp

sudo ufw allow 21/tcp

```


### 8. Test the FTP Server

You can test the FTP server using an FTP client or the command line. To connect via command line, use:

```bash

ftp localhost

```


Then, enter the username (`ftpuser`) and password when prompted.


### 9. Additional Configuration (Optional)

For a more secure setup, consider the following additional configurations:


- **Disable anonymous access**: Ensure `anonymous_enable=NO` is set.

- **Use FTP over SSL/TLS**:

  - Generate SSL certificates:

    ```bash

    sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/vsftpd.key -out /etc/ssl/certs/vsftpd.crt

    ```

  - Configure vsftpd to use SSL:

    ```plaintext

    ssl_enable=YES

    rsa_cert_file=/etc/ssl/certs/vsftpd.crt

    rsa_private_key_file=/etc/ssl/private/vsftpd.key

    ```

- **Restrict users to their home directories**:

  - Ensure `chroot_local_user=YES` is set.

  - Add users to the `chroot_list` by creating and editing the file `/etc/vsftpd.chroot_list`:

    ```bash

    sudo nano /etc/vsftpd.chroot_list

    ```

  - Add usernames to the file, one per line.


### Restart vsftpd Service

After making any changes to the configuration, restart the `vsftpd` service to apply them:

```bash

sudo systemctl restart vsftpd

```


Your FTP server should now be set up and ready to use on Kali Linux. If you need further customization or face any issues, refer to the `vsftpd` documentation or ask for more specific help.


The error "500 OOPS: vsftpd: refusing to run with writable root inside chroot()" occurs because `vsftpd` is refusing to run with a writable root inside a chroot jail, which is a security measure. To fix this, you need to adjust the permissions of the home directory or configure `vsftpd` to allow this setup.


Here's a step-by-step guide to resolve this issue:


### 1. Adjust Directory Permissions


You need to make the home directory non-writable by the user. Here’s how you can do it:


```bash

sudo chmod a-w /home/maverick

```


Then create a subdirectory within the user's home directory that the user can write to:


```bash

sudo mkdir /home/maverick/ftp

sudo chown maverick:maverick /home/maverick/ftp

sudo chmod 755 /home/maverick/ftp

```


### 2. Allow Writable Root Inside Chroot


Alternatively, you can allow writable root directories inside the chroot by enabling `allow_writeable_chroot` in the `vsftpd` configuration. This is less secure but can be used if adjusting directory permissions is not suitable for your use case.


Open the `vsftpd` configuration file:


```bash

sudo nano /etc/vsftpd.conf

```


Add or modify the following line:


```plaintext

allow_writeable_chroot=YES

```


### 3. Restart vsftpd Service


After making changes to the configuration, restart the `vsftpd` service to apply them:


```bash

sudo systemctl restart vsftpd

```


### 4. Test FTP Login


Now, try logging in again:


```bash

ftp localhost

```


Enter your username and password when prompted.


### Additional Tips


- **Check for Configuration Issues**: Ensure there are no conflicting settings in the `vsftpd.conf` file.

- **Verbose Logging**: Enable verbose logging in `vsftpd` to get more detailed information in case of issues:

  ```plaintext

  log_ftp_protocol=YES

  ```

- **File Permissions**: Make sure the FTP user's home directory and its subdirectories have appropriate permissions and ownership.


### Example vsftpd.conf Configuration


Here’s an example configuration for reference:


```plaintext

listen=YES

anonymous_enable=NO

local_enable=YES

write_enable=YES

local_umask=022

dirmessage_enable=YES

use_localtime=YES

xferlog_enable=YES

connect_from_port_20=YES

chroot_local_user=YES

allow_writeable_chroot=YES

secure_chroot_dir=/var/run/vsftpd/empty

pam_service_name=vsftpd

rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem

rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key

ssl_enable=NO

```


By following these steps, you should be able to resolve the "500 OOPS" error and successfully log in to the FTP server on Kali Linux.

Comments

Popular posts from this blog

How To Customize Linux Bootloaders ... #customization #linuxcustomization #kalilinuxcustomization

Linux Commands part - 2 #kali