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
- Login to your Linux server
Installvsftpd
in your server instance viasudo apt-get install vsftpd -y
. once installation is down, the ftp service will start automatically, you can check viasudo netstat -nltp | grep 21
, which tells a certain process is listening port 21. Alternately you can manually start the service viasudo systemctl start vsftpd.service
. - Create directory for your ftp service.
sudo mkdir /home/uftp
andsudo touch /home/uftp/welcome.txt
will create a directory called 'uftp' and filewelcome.txt
in your directory. - 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 viasudo passwd uftp
, you will be required to specify the password twice.
-
- Allow the files can be accessed via ftp
By default you are not allowed to access any file via ftp, commandsudo rm /etc/pam.d/vsftpd
uncover the permission. - Specify your created user can and can only access via ftp
Commandsudo usermod -s /sbin/nologin uftp
can restrict your user can only access via ftp. Detailed access permission can be specified viasudo 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
- 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 viasudo chmod a+w /etc/vsftpd.user_list && vim /etc/vsftpd.user_list
and add user 'uftp' in this file. - Specify the directory permission
sudo chmod a-w /home/uftp
andsudo 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. - Start your vsftpd service
sudo systemctl restart vsftpd.service
- Access you remote ftp via FTP client
- Windows
In File Explorer you can enter below URLftp://[user_name]:[password]@[your_cloud_vm_public_ip]
. - Mac
In *Finder app, click Go in menu and select Connect to Server (or userCommand + K
hot key), enter URLftp://your_cloud_vm_public_ip]
, enter your username and password in pop-up screen, you will be logged in.
- Windows
- FTP Client
FileZilla is a cross-platform ftp client that supports both Windows and Mac.