Linux — FTP Setup

Published 2023-01-07 22:38 615 words 4 min read

A step-by-step beginner-friendly tutorial for setting up an FTP service on Linux

FTP

yum Configuration

This experiment uses a Linux system in its initial state Here I am using redhat9

  1. Configure yum
    • Configuration reference
name=9-stream_BaseOS
enable=1
gpgcheck=0
baseurl=https://mirrors.ustc.edu.cn/centos-stream/9-stream/BaseOS/x86_64/os/

[AppStream]
name=9-stream_AppStream
enable=1
gpgcheck=0
baseurl=https://mirrors.ustc.edu.cn/centos-stream/9-stream/AppStream/x86_64/os/

Remember to make a backup

  1. Disable the subscription on redhat9
    • I found downloads were very slow with the subscription enabled, so I chose to disable it.
# Modify the following two configuration files, change the value of enabled to 0
vi /etc/yum/pluginconf.d/product-id.conf
vi /etc/yum/pluginconf.d/subscription-manager.conf
  1. Clear the cache
    • yum clean all
  2. Build the server cache
    • yum makecache

FTP Installation

yum install -y ftp
yum install vsftpd

Create the Shared Folder and User

# Create the shared folder
mkdir -p /test/ftp
touch /test/ftp/100

mkdir -p /test/ftp/B
touch /test/ftp/B/200

# Create the ftp user and password
useradd fff
passwd fff

# Grant permissions
chown ftp /test/ftp/B
chown 6 /test/ftp/B

Modify the Main Configuration

  1. Make a backup
mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
  1. Because the configuration contains many unneeded lines commented out with #, we need to use grep -v '#'
grep -v '#' /etc/vsftpd/vsftpd.conf.bak >/etc/vsftpd/vsftpd.conf 

grep -v or —invert-match : displays all lines that do not contain the matching text.

  1. Modify vsftpd.conf
# vsftpd.conf is located in /etc/vsftpd/
cd /etc/vsftpd/

vi vsftpd.conf

It shows as follows

anonymous_enable=YES # Allow anonymous users to log in
local_enable=YES # Allow local (system) users to log in
write_enable=YES # Allow uploading
local_umask=022 # Default umask
dirmessage_enable=YES

xferlog_enable=YES # Save the transfer log to /var/log/vsftpd.log
xferlog_file=/var/log/xferlog

connect_from_port_20=YES # Use port 20 for data transfer
xferlog_std_format=YES
ftpd_banner=Welcome to use my test ftp server. # Welcome banner

listen=NO # # Run in standalone mode on ipv4
listen_ipv6=YES # If you don't need to listen, comment it out and change listen=YES. If you need it, keep these two lines unchanged.

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

# Lines to add for anonymous
anon_root=/fhy/test/11 # The directory for anonymous login
anon_upload_enable=YES
anon_mkdir_write_enable=YES

# Lines to add for local users
local_root=/fhy/test
chroot_local_user=YES
allow_writeable_chroot=YES
# This step can be skipped because we are only doing a local experiment.

# Add the following configuration parameters to enable passive mode, set the directory local users land in after login, and the port range that the cloud server can use for data transfer.
local_root=/var/ftp/test
allow_writeable_chroot=YES 
pasv_enable=YES 
pasv_address=xxx.xx.xxx.xx #Change to the public IP of your Linux cloud server pasv_min_port=40000 
pasv_max_port=45000
  1. Add excepted users

You can skip this step if you have no need for excepted users

Run the following commands to create and edit the chroot_list file.

vim /etc/vsftpd/chroot_list

Press i to enter edit mode and enter a username, with one username per line
After finishing, press Esc and type :wq to save and exit.

Firewall Rules and Security Mechanisms

  1. Allow ports 21 and 20
iptables -I INPUT -p tcp --dport 61001:62000 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 61001:62000 -j ACCEPT
iptables -I INPUT -p tcp --dport 20 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 20 -j ACCEPT
iptables -I INPUT -p tcp --dport 21 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 21 -j ACCEPT
  1. Or you can simply disable the firewall

  2. setenforce 0 # Disable the Linux security mechanism

Restart the FTP Service

systemctl restart vsftpd

Point DNS to Yourself

Method one
vim /etc/resolv.conf #After entering, modify and add the following
nameserver 192.168.100.10 #Your own IP

Method two
vim /etc/sysconfig/network-script/ifcfg-NetworkAdapter
DNS1=IP address

Either method, choose one
You can have multiple DNS servers, which are used in order

Verification Omitted

If you enjoyed this, leave a comment~

... Page views
© 2021 - 2026 Vullfin @VV
Powered by theme astro-koharu · Inspired by Shoka