Preface: Common ownCloud Path

(This is part of My ownCloud Adventure)

For any adventure to come to a successful conclusion, the proper preparations must first be made.

With my previous experience working with the Raspberry Pi I was able to quickly get a dedicated server setup and connected to my Synology NAS via NFS.

I should mention here, to plant a seed of thought, that throughout my endeavors the security posture of my system has been a constant consideration.  As an example, with my NFS configuration there are mounts available on my network that I did not give my ownCloud host access to… I am just not comfortable with some files being remotely accessible.

While not exhaustive, there are some common tasks that should probably be performed when setting up a new Raspbian instance:

SD Card Images

Throughout my adventure I made extensive use of Win32 Disk Imager to create images of the SD card.  This allowed me to configure common features once and just reload an image to start over if needed.

For example, I have an image that I created after performing my basic Raspbian updates and configurations.  After that I have an image with SSL certs and MySQL already taken completed.  This definitely made it much easier to go from Apache2, to lighttpd and finally end up at nginx with a “clean” system.

SSL Certs

To allow any of the webservers to utilize HTTPS, generating SSL certificates is the first task.  There are MANY resources available out there, but here are the basic commands I performed.

  1. cd /etc/sll
  2. sudo mkdir localcerts
  3. sudo openssl req -newkey rsa:2048 -x509 -days 365 -nodes -out /etc/ssl/localcerts/myServer.fqdn.pem -keyout /etc/ssl/localcerts/myServer.fqdn.key
  4. sudo chmod 600 localcerts/meister*

These commands result in 2 files as output:  a PEM certificate & a key.  Both are used by any webserver to enable HTTPS.

You will be asked a number of questions during key generation.  Since this results in a self-signed key, answer them however you like.  Except for the FQDN question, I’m not sure any of them even technically matter.  And in the case of the FQDN question, I didn’t care if its value matched my dynamic DNS name or not.

The one important technical detail is that if you do not want to enter a password every time your webserver starts, then do not enter a password when prompted.

Good Resources:


ownCloud supports multiple database backends, but I chose MySQL since its familiar to me (although I do wish MariaDB were available in the Raspbian repository).

  1. sudo aptitude
    1. Install MySQL server
    2. The install will ask for a ‘root’ password for your new database server
  2. mysql_secure_installation
    • A script that performs a number of standard bets practice configurations.  Be sure to follow its recommendations!
  3. mysql -u root -p
    • No need to put your password in as an option, you will be prompted
  4. At the “mysql>” prompt
    • create database myOcDbase;
    • create user ‘myOcUser’@’localhost’ identified by ‘myUserPass’;
    • create user ‘myOcUser’@’’ identified by ‘myuserPass’;
    • grant all privileges on myOcDbase.* to ‘myOcUser’@’localhost’;
    • grant all privileges on myOcDbase.* to ‘myOcUser’@’’;
    • exit

Good Resource:

Acquiring ownCloud

Getting a hold of ownCloud is not difficult and can be accomplished via various means.

I originally dabbled with manually adding an ownCloud repository to my system’s repo list.  I just followed the instructions found for Debian off ownCloud’s Linux packages install link.

  1. cd /etc/apt/sources.list.d
  2. sudo nano owncloud.list
    • Enter:  “deb /”
    • save and exit
  3. cd
  4. wget
  5. apt-key add – < Release.key
  6. sudo apt-get update
  7. sudo apt-get install owncloud

While this method did work and is not a bad way to go, especially considering its many advantages… I was unsure of how quickly the repository would be updated with new versions, so I instead elected to go with the manual install.

  • cd
  • wget
    • As versions change, this link will change.  So be sure to get the latest Tar link.
  • tar -xjvf owncloud-5.0.10.tar.bz2
  • mv owncloud owncloud_5.0.10
  • cp -r owncloud_5.0.10 /var/www
  • cd /var/www
  • sudo chmod -R www-data:www-data owncloud_5.0.10
  • sudo ln -s owncloud_5.0.10 owncloud
    • Using a symbolic link in this fashion can help in the future with manual updates.  Just follow ownCloud’s manual update instructions and pre-position the latest version’s directory under /var/www and re-do the symlink for a quick and easy upgrade

And that seems to wrap up the common activities across each of the volumes in my adventure.

Raspbian using SD card & USB thumb drive

Sub-Topic: Creating a backup image of your Raspbian SD card

Decided to try moving my actual linux partition from the standard SD card location to a USB memory stick.

I did this without fully understanding the benefits (or cons).  🙂

I knew people had done this previously with USB hard drives.  Its possible this will reduce the likelihood of the SD card becoming corrupted.  I’m not sure if it provides any performance (read/write) improvements.

So in summary… I just did it… To do it.


  • My primary resource for getting this done was: Raspbian on Raspberry Pi using SD card + USB memory stick
  • I primarily use a Win7 laptop, so I’ll be differing from the above link in the details, but the overall concepts remain the same.
  • When working with any images I used the Win32 Disk Imager program (v0.7).
  • I did all this after already having Raspbian working and configured with an SD card


  1. Determine the device name of the USB memory stick
    1. This can be accomplished via “dmesg” as seen at the above link.
    2. An alternative method is to “sudo tail -f /var/log/messages” prior to putting the memory stick in.  When you put the memory stick in log messages will appear similar to the “dmesg” format.
    3. My memory stick was at “/dev/sda”
    4. Remove the USB memory stick once done
  2. Create a backup image of your SD card
    1. This accomplishes a couple of things.
      1. Creates a nice backup of a working Raspbian image
      2. Makes it so that when you’re successful, the Raspbian image running off your USB stick is already configured and working immediately.  Yes… This was as awesome as it sounds.
    2. With Win32 Disk Imager
      1. Select the SD card drive letter
      2. Type in the name and full path for the backup image (e.g. c:\users\john doe\desktop\rasp_backup.img).  I had to type it in, bringing up the file window only allows selecting an existing img file
      3. Click Read
      4. And wait…
  3. Write the SD card backup image to the thumb drive
    1. Again, using Win32 Disk Imager
      1. Select the thumb drive’s drive letter
      2. Select the backup img file you just created.  You can use the file dialog box this time
      3. Double check that you did selectd the thumb drive’s drive letter
      4. Click Write
      5. And wait…
  4. Prepare the boot SD card
    1. I had a smaller 256MB SD card lying around, so I used it for this purpose
    2. I used Window’s format capability to format the boot SD card
      1. File system:  FAT32 (this is not the default)
      2. Allocation unit size: 1024 (not sure if this is needed, but its what I did… Default was 2048, which probably would have worked)
  5. Copy boot files from USB memory stick to boot SD
    1. Open the USB memory stick via Windows Explorer
    2. Open the boot SD via Windows Explorer (in a separate window)
    3. Copy all displayed files from the USB memory stick to the boot SD
  6. Modify the boot files to point to the USB memory stick
    1. On the boot SD, open “cmdline.txt”  (notepad worked for me)
    2. There is only a single line in the file
    3. Change “root=/dev/mmcblk0p2” to “root=/dev/sda2”
      1. This tells Raspbian to look at the 2nd partition on the USB memory stick instead of the 2nd partition on the SD card
      2. Save.  There should be no issues saving with notepad since you’re editting the middle of the line, so no carriage return issues that could occur… Possibly… I really don’t know in this case.  🙂
      3. Its possible you SD card and USB memory sticks have different device names, but the above is how it looked for me
  7. Put the boot SD and USB thumb drive into your Pi and plug in the power

After I did the above, everything worked for me the first time and with the configuration I had previously working with just an SD card.  Which means I did not have to move my headless Pi to reconnect it to a TV and keyboard and mouse to verify and configure.

Raspbian – Misc To-Done

Misc things I’ve done to configure my Pi for my personal usage.

Most have to be done via “sudo”

  • Create a new user, separate from “pi”
    • Command:  ‘adduser’
    • Appears to be a Debian specific command, different than the usual Linux ‘useradd’
  • Make new user’s primary group be “users”
    • Since I’m connecting to my Synology NAS over NFS, this allows any files I create as the new user to be part of a common group between the Pi and NAS
    • Command: ‘usermod -g users <newuser>’
  • As “pi” user, give new user ‘sudo’ access
    • Command: ‘visudo’
  • Create RSA key for authentication
    • Command: ‘ssh-keygen’
    • Be sure to keep your key safe and retrievable so that access is not lost… Don’t lose your key!
  • Add pub key to “~/.ssh/authorized_keys” file for new user
  • After achieving access via key authentication, disable SSH password authentication
    • Edit /etc/ssh/sshd_config
    • “PasswordAuthentication no”
  • Optional, specify SSH access for accounts
    • Edit /etc/ssh/sshd_config
    • At bottom of the file, add:
      • AllowUsers newUser1 newUser2
    • Good way to leave default “pi” user “active”, but not directly accessible via SSH
  • Changed hostname
    • nano /etc/hosts
    • nano /etc/hostname
    • reboot
  • Install rsync
    • aptitude install rsync
  • rsync backup script caused an error
    • Error: Too many open files
    • Testing solution: edit /etc/security/limits.conf
      • @users     hard     nofile     32768
  • Configure NTP to sync with NAS
    • Edit /etc/ntp.conf
    • Comment out existing lines starting with “server” that look like “server”
    • Add line like “server <nas IP>”
    • Save
    • service ntp restart

To be continued…