> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/linux-server-administrator/servers-configurations-debian/file-transfer-protocol-ftp.md).

# File Transfer Protocol (FTP)

## FTP (File Transfer Protocol)

File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another over a TCP-based network. The default port for FTP servers is TCP port 21.

Install FTP Client Tool

```sh
apt install ftp
```

Connect to an FTP server:

```sh
ftp ftp_connection_ip
```

* Install FTP Server

```sh
apt install vsftpd
```

#### Important Files

* **Main Configuration File:**

  ```sh
  /etc/vsftpd.conf
  ```
* **Default Location for Publicly Available Files:**

  ```sh
  /srv/ftp/
  ```

#### Enable Passive Mode

```sh
vim /etc/vsftpd.conf
```

Add or modify the following lines:

```sh
pasv_enable=YES
pasv_min_port=55000
pasv_max_port=55999
```

#### Start and Enable vsftpd Service

```sh
systemctl start vsftpd
systemctl enable vsftpd
```

**Default Users:** `anonymous`, `ftp`

#### Manage Anonymous Access

* **Unblock Anonymous User:**

  ```sh
  vim /etc/vsftpd.conf
  ```

  Change:

  ```sh
  anonymous_enable=NO
  ```

  To:

  ```sh
  anonymous_enable=YES
  ```

  Restart the service:

  ```sh
  systemctl restart vsftpd.service
  ```
* **Block Anonymous User:**

  ```sh
  vim /etc/vsftpd.conf
  ```

  Change:

  ```sh
  anonymous_enable=YES
  ```

  To:

  ```sh
  anonymous_enable=NO
  ```

  Restart the service:

  ```sh
  systemctl restart vsftpd.service
  ```

#### Allow Regular Users

```sh
vim /etc/vsftpd.conf
```

Uncomment:

```sh
chroot_local_user=YES
```

Add:

```sh
allow_writeable_chroot=YES
```

Restart the service:

```sh
systemctl restart vsftpd.service
```

#### Manage Root User Access

* **Unblock Root User:**

  ```sh
  vim /etc/ftpusers
  ```

  Comment out the root user line. Restart the service:

  ```sh
  systemctl restart vsftpd.service
  ```
* **Block Root User:**

  ```sh
  vim /etc/ftpusers
  ```

  Uncomment the root user line. Restart the service:

  ```sh
  systemctl restart vsftpd.service
  ```

#### Change Default Directory

Create a folder for users:

```sh
mkdir /folder_name
```

Edit the configuration file:

```sh
vim /etc/vsftpd.conf
```

Add:

```sh
local_root=/folder_name
```

Restart the service:

```sh
systemctl restart vsftpd.service
```

#### Manage Access Control Lists

* **Deny List:**

  ```sh
  vim /etc/ftpusers
  ```

  Restart the service:

  ```sh
  systemctl restart vsftpd.service
  ```
* **Allow List:**

  ```sh
  vim /etc/allow_users
  ```

  Add allowed users, then edit the configuration:

  ```sh
  vim /etc/vsftpd.conf
  ```

  Add:

  ```sh
  userlist_enable=YES
  userlist_file=/etc/allow_users
  userlist_deny=NO
  ```

  Restart the service:

  ```sh
  systemctl restart vsftpd.service
  ```
