Mount SharePoint Online (Office 365) in Linux

Connecting to Office365 Sharepoint (or 'OneDrive for Business') by WebDAV requires an existing authentication cookie. You can't log in with a username and password in your WebDAV client. On Windows you can achieve this by adding the Sharepoint site to Internet Explorer's list of Intranet Sites and then logging in with Internet Explorer and ticking 'Keep me logged in', then it will let you map the network drive in Windows Explorer.

The only way I have found to do this on Linux is with Konqueror, because it contains both a web browser and a WebDAV-enabled file browser. You can log in to the Sharepoint site in the Konqueror browser, then the Konqueror file browser can use that cookie to authenticate to WebDAV.


It is indeed possible, but I don't have a smooth solution yet. I'm mounting SharePoint Drives with davfs2. For this to work you have to authenticate with a browser (by simply accessing your SharePoint site). You then have to extract the Cookies named "rtFa" and "FedAuth". They have to be pasted at the end of the file /etc/davfs2/davfs2.conf like so:

add_header Cookie rtFa=<your cookie here>;FedAuth=<your other cookie here>;

Also add the following line:

use_locks 0

To mount the share, I use the URL of the SharePoint-Webinterface-URL of the Share, without the default.aspx at the end. I also entered them into /etc/fstab, so I can easily mount them:

https://myinstitution.sharepoint.com/sites/path/to/my/share/      /path/to/my/mountpoint   davfs   user,rw,noauto  0       0

To get the cookies to the davfs2.conf file, I use Chrome with the cookies.txt Extension, so I can save them to a file cookies.txt with two clicks. Then I wrote a small Ruby-Script which parses this file and adds the line to the davfs2.conf file. I currently have a sympolic link from /etc/davfs2/davfs2.conf to a file on my home directory, but the cleaner way of doing it would be a config file per user (which davfs2 allows afaik). It's far from ideal, but it does the job for now.

#!/usr/bin/ruby

davfsFile = "/path/to/the/file/davfs2.conf"  # Replace this
cookiesFile = "/path/to/the/file/cookies.txt"  # Replace this
cookies = File.read(cookiesFile).split("\n").map{|c| c.split("\t")}
`rm #{cookiesFile}`

cookies.select!{|c| c[5]=="rtFa" || c[5]=="FedAuth"}
cookieline = "add_header Cookie #{cookies[0][5]}=#{cookies[0][6]};#{cookies[1][5]}=#{cookies[1][6]};"

davfsconf = File.read(davfsFile).split("\n")
davfsconf[-1]=cookieline
File.write(davfsFile, davfsconf.join("\n"))

File transfer is fast and usable, directory access is almost unusably slow, something like ls */bla takes 40 s in a directory with 30 entries... I'm investigating the cause and I will post here when I know more...


This works with the latest version of rclone which is 1.50 at the moment:

https://rclone.org/downloads/

OneDrive for Business is basically sharepoint, it works by the rclone setup as described here:

https://rclone.org/onedrive/ (check the limitations!)

So basically you run in a terminal:

rclone config

Then type n, then type a name and choose option 22 after (this may change, but the onedrive option is meant here). Then hit enter twice (client id and secret are not needed) and then n for no advanced config. Then enter y for autoconfig (your browser should open and it's convenient if you're logged in, it will redirect and show a succes message in the browser.

Go back to the terminal and choose 1 for onedrive. This should show you a drive, choose 0. Next message, choose y to confirm, the next y too.

Now you have the config setup, so you can mount the share as:

rclone --vfs-cache-mode writes mount onedrive: ~/OneDrive

where onedrive is the name of the share you created and ~/OneDrive is the folder in your home directory where you mount it.

If something goes wrong with mounting, you can umount with:

fusermount -uz ~/OneDrive/

You may have noticed that shared folders are not there. It's not supported in rclone at the moment for the business version. To work around that, you can use WebDAV config to mount it. More on that can be found here:

https://rclone.org/webdav/

for vendor choose sharepoint so your config looks something like:

[onedriveShared]
type = webdav
url = https://domain.sharepoint.com/personal/firstname_lastname_domain_com/Documents
vendor = sharepoint
user = [email protected]
pass = encryptes_pass

The issue here is that you would need to add this for every share. Unfortunately Microsoft didn't deem it necessary to support Linux so my advice is and was to stay away from their products and use the ones that work out of the box.


So I do recognize that this question is quite old, though I was searching for this today and could not find any good answers.

I found that what you want to do is go to "https://office.com" and click sign in, from here sign in with your office 365 account as normal Once you are signed in, click on onedrive, you should see a screen similar to this Screen with onedrive office 365 loaded

Once you see this screen, your sharepoint cookie is loaded. you'll see my URL is https://alicesworld-my.sharepoint.com/personal/alice_alicesworld_tech//_layouts/15/onedrive.aspx So what you want to do is REMOVE the last 3 paths in the URL, and add Documents/ like this: https://alicesworld-my.sharepoint.com/personal/alice_alicesworld_tech/Documents/ then change https:// to webdavs://

your final URL should be webdavs://XXXX.sharepoint.com/personal/XXX_XXX_XXX/Documents/

this URL will work in both Konqueror and Dolphin

Screenshot of webdavs onedrive working in konq

To add this folder as a network drive in Dolphin,

Go to the sidebar and click Network then at the top click "Add Network Folder" Click WebFolder (WebDav)

Here the Name can be anything you would like,

Keep the user Field blank

For servername, put the URL without the path,for me thats "alicesworld-my.sharepoint.com"

For folder, put the rest of the URL, for me thats "/personal/alice_alicesworld_tech/Documents/"

finally click the "Use Encryption" Checkmark

Your final result should look something like this Picture of KDE Network Wizard

After this unfortunately long process, everything should work as intended Picture of onedrive folder in dolphin

  • Note, to get dolphin to work, you still have to do the konqueror steps first, this is because you need the Authentication cookie for it to connect, and konqueror is what stores it