參考:http://www.krizna.com/ubuntu/setup-ftp-server-ubuntu-16-04/
https://github.com/samvera-deprecated/hydradam/wiki/Sample-vsftpd.conf >> 範例 vsftp.conf 檔
1.安裝 設定 VSFTP
Step 1 » Update the repository and install vsftpd package using below commands.
krizna@leela:~$ sudo apt update
krizna@leela:~$ sudo apt install vsftpd
Step 2 » Copy the original configuration file for a backup.
krizna@leela:~$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bk
1) FTP configuration.
2) Secure FTP ( FTPS ).
3) SFTP configurarion.
Setup FTP server on ubuntu 16.04
Lets do a basic FTP configuration.
Step 3 » Edit /etc/vsftpd.conf file and make the changes as below.
Uncomment below lines.
write_enable=YES
Add below lines at the end of the file. The first line is to keep all non-chroot users jailed.
local_umask=022
chroot_local_user=YES
Other 2 lines are for the passive port range.
allow_writeable_chroot=YES
pasv_min_port=40000
pasv_max_port=40100
Step 4 » Now restart vsftpd service and check the status.
krizna@leela:~$ sudo systemctl restart vsftpd
krizna@leela:~$ sudo systemctl status vsftpd
● vsftpd.service - vsftpd FTP server
Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-02-25 14:32:35 IST; 3min 57s ago
Process: 1955 ExecStartPre=/bin/mkdir -p /var/run/vsftpd/empty (code=exited, status=0/SUCCESS)
Main PID: 1958 (vsftpd)
Tasks: 1 (limit: 512)
Memory: 392.0K
CPU: 39ms
CGroup: /system.slice/vsftpd.service
└─1958 /usr/sbin/vsftpd /etc/vsftpd.conf
Feb 25 14:32:35 leela systemd[1]: Starting vsftpd FTP server...
Feb 25 14:32:35 leela systemd[1]: Started vsftpd FTP server.
Status should be active and running.If the service is failed to start, Troubleshoot yourself by commenting the lines one by one and check the status after service restart.
Step 5 » Now create an user to test FTP server. Use /usr/sbin/nologin shell to limit access.
krizna@leela:~$ sudo useradd -m jack -s /usr/sbin/nologin
krizna@leela:~$ sudo passwd jack
Step 6 » Add “/usr/sbin/nologin” to /etc/shells file to enable login access for the users who uses nologin shell.
krizna@leela:~$ echo "/usr/sbin/nologin" | sudo tee -a /etc/shells
Test your FTP configuration. Try to connect from ftp client.
[root@localhost ~]# ftp 192.168.22.16
Connected to 192.168.22.16 (192.168.22.16).
220 (vsFTPd 3.0.3)
Name (192.168.22.16:root): jack
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
2.FTP出現權限不足問題
把使用者名稱加入群組
sudo chown -R 你的使用者名稱.www-data /var/www