See more: https://wiki.ubuntu.org.cn/Vsftpd

Concept

  • vsftpd: Very Secure FTP Daemon

    Install

    1. $ sudo apt install vsftpd

    Start

    vsftpd is started automatically after installed it.
    1. $ service vsftpd status
    2. vsftpd.service - vsftpd FTP server
    3. Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
    4. Active: active (running) since Wed 2022-01-26 14:57:58 CST; 16min ago
    5. Main PID: 843765 (vsftpd)
    6. Tasks: 1 (limit: 4612)
    7. Memory: 1.3M
    8. CGroup: /system.slice/vsftpd.service
    9. └─843765 /usr/sbin/vsftpd /etc/vsftpd.conf
    Or you can manually controll it using service:
    1. $ sudo service vsftpd start
    2. $ sudo service vsftpd restart
    3. $ sudo service vsftpd stop

    Access

    Configure vsftpd.conf

    1. $ sudo vim /etc/vsftpd.conf
    2. ...
    3. pasv_min_port=20001
    4. pasv_max_port=21000
    5. ...

    Configure firewall

    1643187507(1).png

    Access with Windows Explorer

    Login

    ftp://dev.ikiss.it or ftp://lighthouse@dev.ikiss.it or ftp://lighthouse:passwd@dev.ikiss.it
    1643187943(1).png
    1643188154(1).png

    Download

    ftp-win-1.gif

    Access with cli

    local access

    1. $ ftp localhost
    2. Connected to localhost.
    3. 220 (vsFTPd 3.0.3)
    4. Name (localhost:lighthouse):<Enter>
    5. 331 Please specify the password.
    6. Password:*******
    7. 230 Login successful.
    8. Remote system type is UNIX.
    9. Using binary mode to transfer files.
    10. ftp> ls
    11. 200 EPRT command successful. Consider using EPSV.
    12. 150 Here comes the directory listing.
    13. drwxrwxr-x 5 1001 1001 4096 Jan 05 12:31 rocket.chat
    14. drwxrwxr-x 3 1001 1001 4096 Jan 25 18:21 scp_files
    15. 226 Directory send OK.
    16. ftp>

    remote access

    1. $ pftp 1.117.98.204
    2. Connected to 1.117.98.204.
    3. 220 (vsFTPd 3.0.3)
    4. Name (1.117.98.204:ronnie): lighthouse
    5. 331 Please specify the password.
    6. Password:
    7. 230 Login successful.
    8. Remote system type is UNIX.
    9. Using binary mode to transfer files.
    10. ftp> ls
    11. 227 Entering Passive Mode (1,117,98,204,79,205).
    12. 150 Here comes the directory listing.
    13. drwxrwxr-x 5 1001 1001 4096 Jan 05 12:31 rocket.chat
    14. drwxrwxr-x 3 1001 1001 4096 Jan 26 17:20 scp_files
    15. 226 Directory send OK.
    16. ftp> cd scp_files
    17. 250 Directory successfully changed.
    18. ftp> ls
    19. 227 Entering Passive Mode (1,117,98,204,78,152).
    20. 150 Here comes the directory listing.
    21. drwxrwxr-x 2 1001 1001 4096 Jan 25 17:48 Nginx
    22. -rw-r--r-- 1 1001 1001 1966 Jan 25 18:21 default.conf
    23. -rwxrwxr-x 1 1001 1001 23696 Jan 25 17:50 dev.do-it.cool.zip
    24. -rwxrwxr-x 1 1001 1001 295115 Jan 26 17:20 me1.jpg
    25. -rwxrwxr-x 1 1001 1001 139377 Jan 26 17:20 me2.jpg
    26. -rwxrwxr-x 1 1001 1001 164668 Jan 26 17:20 me3.jpg
    27. -rwxrwxr-x 1 1001 1001 133431 Jan 26 17:20 me4.jpg
    28. -rwxrwxr-x 1 1001 1001 132827 Jan 26 17:20 me5.jpg
    29. -rwxrwxr-x 1 1001 1001 159251 Jan 26 17:20 me6.jpg
    30. -rwxrwxr-x 1 1001 1001 143987 Jan 26 17:20 me7.jpg
    31. -rwxrwxr-x 1 1001 1001 1129861 Jan 25 17:46 retail.tar
    32. 226 Directory send OK.
    33. ftp> get me1.jpg
    34. local: me1.jpg remote: me1.jpg
    35. 227 Entering Passive Mode (1,117,98,204,80,198).
    36. 150 Opening BINARY mode data connection for me1.jpg (295115 bytes).
    37. 226 Transfer complete.
    38. 295115 bytes received in 0.11 secs (2.5194 MB/s)
    39. ftp> !ls
    40. me1.jpg
    41. ftp> exit
    42. 221 Goodbye.

    Allow upload and delete

    1. $ sudo vim /etc/vsftpd.conf
    2. ...
    3. write_enable=YES
    4. ...
    5. $ sudo service vsftpd restart

    Allow anonymous

    allowing downloading and uploading ```bash $ sudo vim /etc/vsftpd.conf … anonymous_enable=YES anon_upload_enable=YES # need write_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES # deleting and renaming … $ sudo service vsftpd restart

$ sudo mkdir /srv/ftp/upload $ sudo chown ftp:ftp /srv/ftp/upload/

  1. <a name="gxlBA"></a>
  2. ## Logs
  3. ```bash
  4. $ sudo tail -f /var/log/vsftpd.log
  5. Wed Jan 26 15:09:30 2022 [pid 848661] CONNECT: Client "::ffff:117.81.208.104"
  6. Wed Jan 26 15:09:32 2022 [pid 848656] [anonymous] FAIL LOGIN: Client "::ffff:117.81.208.104"
  7. Wed Jan 26 15:09:33 2022 [pid 848669] CONNECT: Client "::ffff:117.81.208.104"
  8. Wed Jan 26 15:09:36 2022 [pid 848668] [anonymous] FAIL LOGIN: Client "::ffff:117.81.208.104"
  9. Wed Jan 26 15:10:20 2022 [pid 848967] CONNECT: Client "::ffff:117.81.208.104"
  10. Wed Jan 26 15:10:22 2022 [pid 848966] [anonymous] FAIL LOGIN: Client "::ffff:117.81.208.104"
  11. Wed Jan 26 15:10:27 2022 [pid 848986] CONNECT: Client "::ffff:117.81.208.104"
  12. Wed Jan 26 15:10:29 2022 [pid 848985] [anonymous] FAIL LOGIN: Client "::ffff:117.81.208.104"
  13. ^C
  14. $

More configurations

allow or deny

  • userlist_enable Default: NO
  • userlist_deny Default: YES
  • userlist_file Default: /etc/vsftpd.user_list | | userlist_deny = YES | userlist_deny = NO | | —- | —- | —- | | userlist_enable = YES | users in userlist_file are denied | users in userlist_file are allowed | | userlist_enable = NO | All users are allowed. | |

limit access

  • chroot_local_user=YES
  • chroot_list_enable=YES
  • chroot_list_file=/etc/vsftpd/chroot_list

    NOTE: when a user is jailed, he must have no write access on his home dir.

chroot_local_user= YES chroot_local_user= NO
chroot_list_enable= YES All users are jailed, but users listed in chroot_list_file are NOT jailed. All users are NOT jailed, but users listed in chroot_list_file are jailed.
chroot_list_enable= NO All users are jailed. All users are NOT jailed.

Dedicated user for ftp

Create ftp user

$ sudo adduser ftper
...

Configure

# /etc/vsftpd.conf
userlist_enable=YES
userlist_deny=NO
# /etc/vsftpd.user_list
ftper

Connect

ftp://ftper@dev.ikiss.it
ftp://ftper:xxx@dev.ikiss.it