Skip to content

Instantly share code, notes, and snippets.

@stevenkaspar
Last active February 25, 2019 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenkaspar/50658300a15e1faa486ed1f085492154 to your computer and use it in GitHub Desktop.
Save stevenkaspar/50658300a15e1faa486ed1f085492154 to your computer and use it in GitHub Desktop.
FTP(S) using vsftpd

Scripts and config files for setting up FTP and FTPS on Ubuntu 18.04 LTS (works elsewhere but that is where I've used these steps)

  1. Run install.sh
  2. Paste vsftpd.conf into /etc/vsftpd.conf
  3. nano adduser.sh and paste in script
  4. chmod +x adduser.sh
  5. nano adduser-admin.sh and paste in script
  6. chmod +x adduser-admin.sh

Add users with

./adduser.sh new_ftp_user password

Add non-chroot users with

./adduser-admin.sh new_ftp_user password
./adduser "$1" "$2"
sudo echo "$1" | sudo tee -a /etc/vsftpd.nonchroot_list
sudo useradd -m $1
echo "$1:$2" | sudo chpasswd
sudo mkdir /home/$1/ftp
sudo chown nobody:nogroup /home/$1/ftp
sudo chmod a-w /home/$1/ftp
sudo ls -la /home/$1/ftp
sudo mkdir /home/$1/ftp/files
sudo chown $1:$1 /home/$1/ftp/files
sudo echo "$1" | sudo tee -a /etc/vsftpd.userlist
if id "$1" >/dev/null 2>&1; then
echo "USER CREATED"
else
echo "USER NOT CREATED"
sudo rm -rf /home/$1
fi
sudo apt update
sudo apt install vsftpd
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.nonchroot_list
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
pasv_address=IP4_EXTERNAL_ADDRESS
user_sub_token=$USER
local_root=/home/$USER/ftp
pasv_min_port=10000
pasv_max_port=50000
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
require_ssl_reuse=NO
ssl_ciphers=HIGH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment