Lauren Malhoit walks you through the steps for setting up a Linux Ubuntu 12.04 server with a second hard drive as a VMware virtual machine.
I've been playing around with different ways of implementing FTP lately—that is, whether to use Windows, Linux, or just some sort of storage device with built-in FTP capabilities. I spent a bit of time creating an Ubuntu 12.04 FTP server and thought I'd share that experience in this post. As mentioned before, I'll be going through setting up a Linux Ubuntu 12.04 server, with a second hard drive, as a VMware VM. I chose vsftpd as my FTP server.
Install Ubuntu 12.04 Virtual Machine
I'm assuming you're familiar with setting up VMs, so these steps are somewhat vague, noting some caveats.
1. Download the Ubuntu 12.04 server ISO and create a new VM with it.
2. Step through the initial Ubuntu configuration wizard. When it asks you to specify how you'd like to partition the boot volume, make sure you specify "Guided with LVM."
3. Log in with the username you created during the setup wizard and then type "sudo su root" to change to root. Changing to the root user is optional, but if you decide not to do it, you will need to type "sudo" before all of your commands.
4. Change to a static IP address:
root:/# nano /etc/network/interfaces
This takes you to the interfaces config, which you'll need to alter to reflect your IP schema. For example:
iface eth0 inet static
netmask 255.255.255.0gateway 10.0.0.1
Within the nano environment, type ctrl + o to write the changes. Then press ENTER to save it to the same file name. Finally press ctrl + x to exit nano.
Add a second hard drive
It's nice to put data on a second hard drive. That way you can upgrade your OS and troubleshoot problems without having to worry too much about losing your data.
1. Edit the settings on your VM and add a hard drive.2. List the current disks on your machine and see the second hard drive (ex: Figure A shows sdb)
root:/# fdisk -l
3. Partition the second hard drive
root:/# fdisk /dev/sdb
Type the following while in the fdisk menu:
n (to create a new disk)
p (to make it a primary disk)
1 (to name the disk /sdb1)
Except the defaults for the first sector and last sector by pressing ENTER.
w (to write the changes)
4. Update the kernel with the changes
root:/# partrobe /dev/sdb
5. Format the new partition
root:/# mkfs /dev/sdb1 -t ext4
Mount the home directory to the new partition
After I create a user for my FTP, I'll want them to store their data on the second hard drive. So, you play kind of a shell game to mount /home to the new partition without losing any data that is currently in your /home directory.
1. Mount the new partition
root:/# mkdir /mnt/home1 root:/# mount -t ext4 /dev/sdb1 /mnt/home1
2. Copy data from your old home to the new home1
root:/# cd /home root:/# find . -depth -print0 | cpio —null —sparse -pvd /mnt/home1
3. Check that everything copied
root:/# cd /
root:/# cd /mnt/home1root:/# ls
‘ls' should list all the files that were copied.
4. Unmount /mnt/home1
root:/# umount /mnt/home1
5. Rename the old home directory
root:/# mv /home /home_old
6. Create a new home directory
root:/# mkdir /home
7. Mount the new home directory to the second hard drive
root:/# mount /dev/sdb1 /home
8. Make this change permanent so that it remains mounted even after a restart by altering the fstab file
root:/# nano /etc/fstab
Add this line to the file:
/dev/sdb1 /home ext4 nodev,nosuid 0 2
Type ctrl + o, ENTER, ctrl + x.
9. Check then double check after a restart
root:/# cd /home root:/# ls
10. Now you can remove the old home directory
root:/# rm -r /home_old
1. Install VSFTPD
root:/# apt-get install vsftpd
Type Y to continue with instal.
2. Change the config file for vsftpd
root:/# nano /etc/vsftpd.conf
Make at least the following changes, however read the man pages to see if there are other configurations you'd like to change, such as adding passive IP addresses and ports or other security enhancements:
a. Remove # from before local_enable=YES to uncomment it.
b. Remove # from before write_enable=YES to uncomment it.
c. Change the no to yes by chroot_local_user (ex: chroot_local_user=YES).
d. Type ctrl+0, ENTER, ctrl+x.
3. Restart the vsftpd service
root:/# service vsftpd restart
4. Create a local user so people can authenticate when trying to connect to the FTP server
root:/# useradd ftp root:/# passwd ftp
Type in password
5. Create a home directory for user ftp
root:/# cd /home
root:/# mkdir ftproot:/# chmod a-w ftp
At this point you should have a working FTP server. You can either connect with a client such as FileZilla, or you can connect using the command line using the command "ftp ip.add.re.ss." If you're setting this up for users outside the network, you may have to check your firewall settings to ensure the proper ports are open, and it may require more work in the vsftpd.conf file depending on if you're using passive or active ftp.