ubuntu 安装 vsftpd

source: https://www.digitalocean.com/community/tutorials/how-to-configure-vsftpd-to-use-ssl-tls-on-an-ubuntu-vps

Introduction

Warning: FTP is inherently insecure! Consider using SFTP instead of FTP.

FTP, or file transfer protocol, was a popular way to transfer files between local and remote computers in the past. The protocol is inherently insecure, so its usage has fallen out of favor.

If you still want to use FTP instead of a more secure alternative like SFTP, which uses the SSH protocol to implement file transfers, you can secure it somewhat by configuring FTP to use SSL.

In this guide, we will configure vsftpd to use SSL certificates on an Ubuntu 12.04 VPS.

Install vsftpd

The vsftpd server is available in Ubuntu's default repositories. You can install it by typing:

sudo apt-get install vsftpd

We now have vsftpd on our server, but we still must configure it.

Configure Basic vsftpd Functionality

The default configuration file is at /etc/vsftpd.conf. Open it with root privileges:

sudo nano /etc/vsftpd.conf

Disable the ability for users to log in anonymously by finding the anonymous_enable parameter and changing it to read "NO":

anonymous_enable=NO

Next, we need to enable user logins that use the local authentication files, since we disabled anonymous access. Uncomment this line:

local_enable=YES

To enable users to make modifications to the filesystem, we will uncomment the write_enableparameter as well:

write_enable=YES

Additionally, uncomment the chroot_local_user option to restrict users to their own home directories:

chroot_local_user=YES

Save and close the file.

Create an FTP User

Because of the way vsftpd secures its chroot jails, the chroot must not be owned by the user and must not be writeable. Because of this, it is best to implement a user specifically for use with FTP.

Create the user like this:

sudo adduser ftpuser

Assign a password and feel free to press "ENTER" through the other prompts. Now, give root ownership of the ftpuser's home directory:

sudo chown root:root /home/ftpuser

We need to create a separate directory within this home directory where files can be uploaded. Then, we need to give this directory over to our FTP user:

sudo mkdir /home/ftpuser/files
sudo chown ftpuser:ftpuser /home/ftpuser/files

Now, we should be able to log in (insecurely) as the ftpuser and upload files to the files directory.

Configure SSL with vsftpd

We need to create some SSL certificates to use with vsftpd. We can do this with the following command:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem

This will create a certificate that will last a year. It will be placed in the /etc/ssl/private/ directory, which we can reference in our configuration file.

Add the SSL Details to the vsftpd Configuration

Open the vsftpd configuration file again with root privileges:

sudo nano /etc/vsftpd.conf

Towards the bottom of the file, you should find a line that matches the SSL certificate we just created:

rsa_cert_file=/etc/ssl/private/vsftpd.pem

We will add the additional SSL info below this.

When we created the certificate, we included both the key file and the certificate in one file, so we can also point our private key line to that:

rsa_private_key_file=/etc/ssl/private/vsftpd.pem

After that, we will add the following lines to force SSL. This will restrict clients that can't deal with TLS, but that is what we want.

ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES

After this we configure the server to use TLS, which is actually a successor to SSL, and preferred:

ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO

Finally, we will require add some additional options to flesh out our configuration file:

require_ssl_reuse=NO
ssl_ciphers=HIGH

Save and close the file.

Now, we need to restart our server for our changes to take effect:

sudo service vsftpd restart

How To Connect to the Server with FileZilla

Most modern FTP clients can be configured to use SSL and TLS encryption. We will be demonstrating how to connect using FileZilla due to its cross platform support.

In the configuration panel, you should see a button on the far left to open "Site Manager". Click this:

FileZilla Open Site Manager

Click on "New Site" in the bottom right corner of the window interface that appears:

FileZilla New Site

Name the new configuration. Fill out the IP address. Under the "Encryption" drop down menu, select "Require explicit FTP over TLS".

For "Logon Type", select "Ask for password". Fill in the ftp user you created in the "User" field:

FileZilla Server Configuration

Click "Connect" at the bottom of the interface. You will be asked for your user's password:

FileZilla user password

You will then be asked to accept the TLS certificate:

FileZilla Server Certificate

You should now be connected with your server with TLS/SSL encryption.

Conclusion

This setup improves the security of FTP, but it still suffers from insecurity when establishing a connection. If at all possible, it is better to switch to SFTP for these kinds of operations. However, if you do decide to go with FTP, you should make sure to use TLS/SSL whenever possible.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值