求助:Ubuntu 16.04中创建新用户FTP登录的简易方法
Hey there! Let's get this FTP access sorted out for your new user on Ubuntu 16.04—this is straightforward once you follow these steps using vsftpd (the go-to FTP server for Ubuntu):
1. Install vsftpd first
First up, install the FTP server package. Open your terminal and run:
sudo apt update && sudo apt install vsftpd
2. Create your new FTP user (and set up their directory)
If you haven't already created the user, do that now:
sudo adduser ftpuser
Follow the prompts to set a password (this is what they'll use to log in via FTP) — you can skip the optional personal info by hitting Enter.
Next, we'll set up a restricted directory structure so the user can't browse outside their own space:
# Create the main FTP root directory sudo mkdir -p /home/ftpuser/ftp # Lock down the root so they can't delete or modify it sudo chown nobody:nogroup /home/ftpuser/ftp sudo chmod a-w /home/ftpuser/ftp # Create a subdirectory they can write files to sudo mkdir /home/ftpuser/ftp/files sudo chown ftpuser:ftpuser /home/ftpuser/ftp/files
3. Tweak the vsftpd configuration
First, back up the original config file just in case:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
Now open the config file with nano:
sudo nano /etc/vsftpd.conf
Find and modify/add these lines (you can use Ctrl+W to search for existing ones):
- Set
anonymous_enable=NO(blocks anonymous FTP access, which is safer) - Make sure
local_enable=YES(allows local users like your newftpuserto log in) - Add or uncomment
write_enable=YES(lets the user upload files) - Add
local_umask=022(sets default permissions for uploaded files) - Add
chroot_local_user=YES(locks the user into their FTP directory) - Add
allow_writeable_chroot=YES(fixes a permission issue with chroot on Ubuntu 16.04) - Add
user_sub_token=$USERandlocal_root=/home/$USER/ftp(points the user to their dedicated FTP directory) - Ensure
listen=NOandlisten_ipv6=YES(matches Ubuntu 16.04's default network setup)
When you're done, save and exit: press Ctrl+O, hit Enter, then Ctrl+X.
4. Restart vsftpd to apply changes
sudo systemctl restart vsftpd
5. Open the firewall (if you're using ufw)
If your Ubuntu system has ufw enabled (which is default), allow FTP traffic:
sudo ufw allow 21/tcp
Test it out
You can test the connection right from your terminal:
ftp localhost
Enter ftpuser as the username and the password you set earlier. Try uploading a test file to the files directory:
put your-test-file.txt files/
If it works, you're good to go! You can also use any FTP client (like FileZilla) from another machine using your server's IP, ftpuser, and password.
That's all! Your new user now has restricted, functional FTP access. If you hit snags, double-check the vsftpd config file for typos — it's easy to miss a line or a comma.
内容的提问来源于stack exchange,提问作者Arun Kumar

