Adding cloud storage as permanent mount to Ubuntu Server 16.04

Many cloud storage services give you the option to mount your online storage as an extra drive on your operating system. This can be done really easy on any operating system that runs a desktop environment. But I wanted to add my storage as a mounted drive on Ubuntu Server, and it does not use a desktop environment so I use WinSCP and Putty to administrate my server.
I did some research on how to mount my cloud storage I use at Stackstorage. In my account info on their website they showed me that the address I have to use for WebDAV should be . This was all the information I needed to get started. Here’s a step by step guide how I did this that you can follow but keep in mind that some commands should be different depending on what cloud storage provider you are using. Click on READ MORE to read the full article.

I’m assuming that you are already connected to your server and have the console in front of you and ready to accept your commands. First we need to install davfs2 and a file editor. I choose nano in this example but it doesn’t have to be nano it can also be whatever editor you are most familiar with. When you decide to use nano but are new to this you should know that when you’re done editing a file you press ctrl+x and then press Y for yes (to save the file) and then press enter to confirm the filename to exit nano. I ran in to some issues with permissions when I used my regular sudo account so I decided to first enable the root account and perform all the commands as root. This is probably not exactly “best practice” so I would advice to disable the root account again after you’re done. To enable to root account just log in with your regular sudo account and enter:

sudo su
passwd root

Create a strong password here for the root user. Now log on as root and begin with installing the required software!

su
apt update
apt install nano davfs2

During the installation you are asked a question. At first I chose the default option NO but I decided I needed to change this afterwards, so I used the following command and changed the option to YES.

dpkg-reconfigure davfs2

Next we are going to create a hidden directory as subfolder in our home directory and copy the default config file there so we can edit an option that will result in an error message if we changed it in the default config file.

mkdir ~/.davfs2
cp /etc/davfs2/davfs2.conf ~/.davfs2/davfs2.conf
nano ~/.davfs2/davfs2.conf

Uncomment or remove the # at line 36 that says # secrets /etc/davfs2/secrets and save the file. We will need to enter our login credentials in a secrets file. For security reasons it would be better not to use the default location /etc/davfs2/secrets but to place it in the ~/.davfs2/ subfolder of the user. Create a new file ~/.davfs2/secrets and don’t forget to point the previous edited config file to the newly created secrets file.

nano ~/.davfs2/secrets

Add the line below to the bottom of the file. Replace username in the address and at the end of the line with your own username & password of course.

username password

nano ~/.davfs2/davfs2.conf
Change secrets /etc/davfs2/secrets to secrets ~/.davfs2/secrets

Now for extra security we will need to change the permissions on the file that contains your login details.

chmod 600 ~/.davfs2/secrets

Next we need to add our user account for the cloud storage to /etc/group after the line davfs2:x:134: It will probably be the last line at the very bottom.

nano /etc/group

Look for davfs2:x:134: and change it in to davfs2:x:134:USERNAME so it will look like:

davfs2:x:134:username

usermod -aG davfs2 root (or your current linux username) will add your user account to the davfs2 group. Now it’s time to logout and log back in again or do a reboot.

Since I already have several disks mounted in subfolders of /mnt I will also need to mount my storage at a new subfolder of /mnt so first make a new folder.

mkdir /mnt/stack

At this point we can already test to see if it works. We will mount the cloud storage just to see if it will work. Keep in mind that mounting it like this will not make it a permanent mount and so it will disappear after rebooting your system. But for now we just want to make sure it works before we continue. Use this command to mount:

mount -t davfs /mnt/stack

Now cd in to that folder and check if you can see the correct files/folders that are on your cloud storage.

cd /mnt/stack
ls -la

The screenshot shows that it works! These are the folder that are located on my cloud storage. I would like to use this storage as a backup location so I want it to always be available, even after rebooting the server. To do this we are going to have to add a new line to /etc/fstab

nano /etc/fstab

Add the line below but adjust it so it fits your needs. It should be written as <WebDav URI> <mount point> <options>. So in my case and this example I added:

/mnt/stack davfs _netdev,x-systemd.automount 0 0

When we examine this line you can see that one of the options is set to _netdev. This means it will wait for the networking service to be up and running before trying to mount it. The option x-systemd.automount wshould make sure that it will be automatically mounted after every reboot. If for some reason this doesn’t work for you, you can use the command mount -a after logging in because it will show you an error message in case of a faulty configuration. Another option would be to add the mount -a command to your /etc/rc.local file.