dsgnr
Posts: 6
Joined: Thu Sep 04, 2014 8:38 am

Public FTP server for noob

Thu Sep 04, 2014 8:45 am

Hello, I currently have a Raspberry Pi I use for XMBC but I have come to a point where I would like to explore different options for my Pi. I am a web developer working predominantly in Wordpress. I keep automated weekly backups of all my websites which are stored locally on the server as well as uploaded to my Dropbox.

The size quota for my Dropbox isn't massive (2.5gb) and one of my websites is 500mb on it's own (photographer with loads of pictures, all optimised before someone says to optimise them). 2.5gb storage isn't a massive amount and without going through a paid option like Amazon S3, I thought I would explore the possibility of having the backups upload themselves to an FTP server onto a USB drive or SSD.

I have looked at tutorials but having no real knowledge of the languages involved (I currently write in PHP, CSS, HTML and JS) I am looking to see whether I am able to create a public FTP where my Wordpress backups can be stored. Ideally as secure as possible so SFTP.

Are there any ways of doing this? If so, are there any requirements/tutorials/tips that would be helpful?

Thanks in advance.

Sorry if this is asked a lot but struggling a little here.

Thanks,
Dan
RPi Model B running XBMC | RPi Model B+ running VSFTPD
What next?

dsgnr
Posts: 6
Joined: Thu Sep 04, 2014 8:38 am

Re: Public FTP server for noob

Thu Sep 04, 2014 1:22 pm

Having done more research, it looks like an SSD is out of the question as no SATA port is available. So I think I'll go down the route of either 1 128GB USB flash or 2x 128GB flash at RAID1.

Is anyone able to help me with this?

From what I gather, I am best to install Raspbian and then set up an FTP server that way...
RPi Model B running XBMC | RPi Model B+ running VSFTPD
What next?

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Public FTP server for noob

Thu Sep 04, 2014 1:47 pm

ssd will work [same as any hard disk] just use a usb to sata enclosure - and plug it into one of the USB sockets -
don't bother with flash as storage {IMO - and that includes ssd] use a real HD
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

dsgnr
Posts: 6
Joined: Thu Sep 04, 2014 8:38 am

Re: Public FTP server for noob

Thu Sep 04, 2014 2:13 pm

Ok I'll look into that.

Still not sure how to go about actually setting all this up? Is there a spool up /spool down feature I can enable? Usually, backups will run every night at midnight
RPi Model B running XBMC | RPi Model B+ running VSFTPD
What next?

dsgnr
Posts: 6
Joined: Thu Sep 04, 2014 8:38 am

Re: Public FTP server for noob

Sun Sep 07, 2014 9:28 am

Ok, I have successfully managed to set up vsftpd and SSL and can connect locally however, I can not connect to my static IP address. I have an Apple Airport Extreme router and I have set port forwarding to port 21 but I don't get anything. Upon doing a local port scan the Pi only seems to display a something on port 22: SSH.

Anyone have any ideas that can help me? I believe I have done everything I need to do!

Also, I haven't connected a HD to this yet, I am just running off a 16gb SD card for now. Do I have to enter anything in the command line to mount the HD and is there a way to default the file system on the new mounted drive? I think I will buy a new 1/2TB portable USB HDD if this makes any difference.

I am not sure what the energy saving settings are on the RPi but I would rather not have the hard drive spinning all the time but only when it's requested, if this is possible?

I don't think there are any other problems I am having. I have had to start again about a thousand times for something that does intact look quite simple!

Below is my current config file:

Code: Select all

# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
#
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=YES
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.

# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
#local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES

# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES

# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# Customization
#
# Some of vsftpd's settings don't fit the filesystem layout by
# default.
#
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/private/vsftpd.pem
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=NO
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=YES
ssl_sslv3=YES


pasv_enable=YES
pasv_min_port=11000
pasv_max_port=11010

RPi Model B running XBMC | RPi Model B+ running VSFTPD
What next?

dsgnr
Posts: 6
Joined: Thu Sep 04, 2014 8:38 am

Re: Public FTP server for noob

Sun Sep 07, 2014 5:26 pm

Ok, everything is working correctly however, I have a few questions.

1. What should really be done to secure the Pi a little more now it's publicly available? Are there any firewalls, brute-force protectors? Should I disable SSH for users except root and Pi I can only imagine what someone who shouldn't get in can do so I'd like to lock it down as much as I can. Should I rename the Pi username? Anyone have any pointers?

2. I have successfully created a new user (called dan for examples sake) and a new directory (called FTP). I have chroot set to Yes in my vsftpd.conf file but the user can still access the / files as they please, although it does not let them change files I believe. Is there a way to completely lock the user 'dan' to the 'ftp' folder? I'd rather not let users apart from myself have access to the / files. Or does it not really matter if they don't have permissions to edit?

I'm brand brand new to this stuff. My only other venture with a Pi is XBMC. Being a web dev, I can get to grips with the languages pretty easily, it's just knowing all the variables I struggle with!

Thanks in advnace.
Sorry for all the questions. I have been browsing around for ages but have not found anything that works yet!

Dan
RPi Model B running XBMC | RPi Model B+ running VSFTPD
What next?

User avatar
socialdefect
Posts: 110
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: Public FTP server for noob

Mon Sep 08, 2014 2:12 am

dsgnr wrote:Ok, everything is working correctly however, I have a few questions.

1. What should really be done to secure the Pi a little more now it's publicly available? Are there any firewalls, brute-force protectors? Should I disable SSH for users except root and Pi I can only imagine what someone who shouldn't get in can do so I'd like to lock it down as much as I can. Should I rename the Pi username? Anyone have any pointers?
The best protection is to use the least possible ammount of services and in this set-up you've got a lot of unnecessary services enabled.
Since you are making backups from a publicly availably webserver you don't need to expose your Pi at all since it can connect to the server anyways using ssh. To create automatic backups you can use rsync or scp from a cron script on your Pi.
Securing ssh is done by denying root logins and password authentication so users can only log in using public key authentication. Most attacks that target ssh try to bruteforce passwords for common user names like: root, mysql, oracle, guest, test, etc.. To completely avoid these attacks you can change the ssh port (below 1024 for else it it vulnerable to other attacks) but this is not always practical.
The first thing you should do after installing Raspbian is to change the root password, add a new user and remove the default user.
2. I have successfully created a new user (called dan for examples sake) and a new directory (called FTP). I have chroot set to Yes in my vsftpd.conf file but the user can still access the / files as they please, although it does not let them change files I believe. Is there a way to completely lock the user 'dan' to the 'ftp' folder? I'd rather not let users apart from myself have access to the / files. Or does it not really matter if they don't have permissions to edit?
I've used vsftpd a couple of times and always had this same problem. not being able to write to / doesn't stop someone that really wants to do something bad. Being able to read config files can be just as dangerous since those contain passwords, api keys and whatever else you have configured. there is a chrooted vsftp deamon package out there that should work but I'd recommend you use a jailed ssh setup or DropBear.
For setting up secure servers there is only one person I know of that knows it all: Falko Timme, the main author for HowToForge.com.
I suggets you install some virtual machine app like VirtualBox, VMware player or KVM and build 2 or 3 of his "perfect Server" HOWTO's to get familar with Linux servers and security hardning.
I'm brand brand new to this stuff. My only other venture with a Pi is XBMC. Being a web dev, I can get to grips with the languages pretty easily, it's just knowing all the variables I struggle with!
The most important thing to learn about Linux is where to find the right documentation, most of it is right under your nose and can be accessed by executing:

Manual page command (man)

Code: Select all

man [i]program-name[/i]
or execute a program or config file with the -h or --help parameter

Code: Select all

[i]program-name[/i] -h
[i]program-name[/i] --help
And all other system documentation can be found under the directory /usr/share/doc and more can be installed using apt-get.
If this docu does not provide you with an answer try popular wiki's and sites like HowToForge.com, TLDP.org, Gentoo wiki, ArchLinux Wiki. And then you can move on to the forums and IRC channels since those are mostly helpfull when you know what's wrong but don't have a fix.
Thanks in advnace.
Sorry for all the questions. I have been browsing around for ages but have not found anything that works yet!

Dan
Never be sorry for asking questions for you might stop asking them.

And btw.. not exactly what you were looking for but it might give you some fresh ideas: Howto: Raspi disk sharing over LAN using autofs
== If it's not broke... I'm not done fixing it! ==

dsgnr
Posts: 6
Joined: Thu Sep 04, 2014 8:38 am

Re: Public FTP server for noob

Mon Sep 08, 2014 8:36 am

Thank you for your very detailed response. It's a great help!

I am backing up about 15 Wordpress installations from multiple servers. Unfortunately a group of customers have opted to go with a hosting company that doesn't allow access to phpMyAdmin, SSH or anything that is remotely useful. So with these servers, unfortunately, SFTP is the only way to back the site up. For this, I am using a programme called InfiniteWP with a remote repository add-on so I can backup to local server, Google Drive or to FTP. So whilst I appreciate there is a better method than SFTP for this task, this is the only method I can use for these servers.

I have read up about using tokens to login to SSH which I think I will definitely look in to. Along with this, is it worth renaming the root username to something a little less generic. And should I rename/remove the Pi username? I am not sure which is the default user, is this user Pi? Whilst I know that someone trying to access will most likely very quickly find out what the device is and know vulnerabilities, I would like to make it as difficult as I can.

I have found a few tutorials on how to limit a user to only one specific folder so I will experiment and post up my findings.

Thank you everyone for your help so far. I am starting to enjoy using my Pi and finding out what else I can do with it!

Dan
RPi Model B running XBMC | RPi Model B+ running VSFTPD
What next?

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Public FTP server for noob

Mon Sep 08, 2014 10:27 am

leave root alone - it is as it is because it is - you do not need to have any root password - just give yourself an account with sudo access - disable the user pi
use ssh keys to login
see
ssh-keygen -t rsa
use sftp via ssh not ftp
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “Beginners”