Enable|Enable FTP service in your linux server

【Enable|Enable FTP service in your linux server】FTP is a file transfer protocol that specifies how to transfer files across the internet, and in this blog, I am going to show how to enable an ubuntu server accessible via FTP.
Prerequisite
You should have an Ubuntu server instance running at hand. You can either apply a free one in AWS or any other cloud PaaS Provider.
Steps

  1. Login to your Linux server
    Install vsftpd in your server instance viasudo apt-get install vsftpd -y. once installation is down, the ftp service will start automatically, you can check via sudo netstat -nltp | grep 21, which tells a certain process is listening port 21. Alternately you can manually start the service via sudo systemctl start vsftpd.service.
  2. Create directory for your ftp service.
    sudo mkdir /home/uftp and sudo touch /home/uftp/welcome.txt will create a directory called 'uftp' and file welcome.txt in your directory.
  3. Create ftp user that can login to your server via ftp
    • sudo useradd -d /home/uftp -s /bin/bash uftp will create user 'uftp', you can specify another name as you like. Once the user is created, specify the password for user via sudo passwd uftp, you will be required to specify the password twice.
  4. Allow the files can be accessed via ftp
    By default you are not allowed to access any file via ftp, command sudo rm /etc/pam.d/vsftpd uncover the permission.
  5. Specify your created user can and can only access via ftp
    Command sudo usermod -s /sbin/nologin uftp can restrict your user can only access via ftp. Detailed access permission can be specified via sudo chmod a+w /etc/vsftpd.conf && vim /etc/vsftpd.conf. A sample specification is given below:
# 限制用户对主目录以外目录访问 chroot_local_user=YES# 指定一个 userlist 存放允许访问 ftp 的用户列表 userlist_deny=NO userlist_enable=YES# 记录允许访问 ftp 用户列表 userlist_file=/etc/vsftpd.user_list# 不配置可能导致莫名的530问题 seccomp_sandbox=NO# 允许文件上传 write_enable=YES# 使用utf8编码 utf8_filesystem=YES

  1. Add your created user to user list
    sudo touch /etc/vsftpd.user_list creates user list file that specifies only users specified here can access the server via ftp. You can modify the file via sudo chmod a+w /etc/vsftpd.user_list && vim /etc/vsftpd.user_list and add user 'uftp' in this file.
  2. Specify the directory permission
    sudo chmod a-w /home/uftp and sudo mkdir /home/uftp/public && sudo chmod 777 -R /home/uftp/public, the fisrt command tells that /home/uftp is only readable, and the second command tells /home/uftp/public is both readable and writable.
  3. Start your vsftpd service
    sudo systemctl restart vsftpd.service
  4. Access you remote ftp via FTP client
    • Windows
      In File Explorer you can enter below URL ftp://[user_name]:[password]@[your_cloud_vm_public_ip] .
    • Mac
      In *Finder app, click Go in menu and select Connect to Server (or user Command + K hot key), enter URL ftp://your_cloud_vm_public_ip], enter your username and password in pop-up screen, you will be logged in.
  • FTP Client
    FileZilla is a cross-platform ftp client that supports both Windows and Mac.

    推荐阅读