How to Sync Microsoft OneDrive with Linux

sync-onedrive-linux-featured

Sometimes lately it can be necessary to use propriety products. Open source enthusiasts would love to have a cloud-based storage facility, but the fact remains that companies like Google, Amazon, Dropbox and Microsoft have cornered the cloud storage market. They offer reliable products for free, and this means that yes, they will scan or read your files in order to comply with legal requests or to serve adverts. It is a fact of life, but this doesn’t mean you shouldn’t use them.

OneDrive is Microsoft’s cloud-based storage offering, and even though it is naturally suited to the Windows platform, it will connect with Linux-based machines with little effort. There are a number of ways to do this, and this is where the onedrive script comes into play.

Onedrive is a CLI-based client that allows you to sync quickly and easily with OneDrive.

In order to install onedrive, first you need to install some dependencies and set up git, unless you already have it. Head to the Terminal and enter one of the following.

For Ubuntu:

If you are using Ubuntu 18.04 or newer, use snap to install dmd:

If not:

For Fedora:

Arch Linux:

After installing the dependencies, fetch the files with git:

And compile and install it:

After you have done this, now you need to authorize onedrive with Microsoft so it can access your account. Simply enter the following in the Terminal:

And it will prompt you to visit the URL to get authorization.

onedrive-authorize-url

Log in to your OneDrive account, and grant the app permission to access your account.

ms-auth

Once this is done, you will be presented with a blank white page. Copy the URL and paste it into the Terminal at the prompt.

onedrive-response-url

That’s it. Onedrive will start downloading all your files in the cloud to your local folder.

You can find the “config” file at the onedrive git folder. To make it active, move it to the “~/.config/onedrive/” folder.

Open the config file. There are two options that you can configure: “sync_dir” and “skip_files.”

  • sync_dir: the location to store your OneDrive files. All files placed in/removed from this folder will be synced to the cloud.
  • skip_files: the file type (or file pattern) that won’t be synced.

Once you have made the changes, save and restart onedrive.

Sync List

If you prefer to use selective sync rather than sync the whole OneDrive folder, you can create a file named “sync_list,” and place it in the “~/.config/onedrive” folder. Inside the file add the relative path (from the synced OneDrive folder) to the files/folders you want to sync.

By default, onedrive doesnt start when the user logs in. To get it to run automatically when you log in, you can either use systemd:

or just add onedrive to your startup application.

Now your OneDrive will sync with your Linux system. How do you sync OneDrive to your setup, and do you prefer other tools? Let us know in the comments section below.

Image credit: Microsoft OneDrive website under a magnifying glass by DepositPhotos

11 comments

  1. Hey! I’m getting an error upon compiling:
    user:~/onedrive $ make
    dmd -g -ofonedrive -O -L-lcurl -L-lsqlite3 -L-ldl -J. src/config.d src/itemdb.d src/log.d src/main.d src/monitor.d src/onedrive.d src/qxor.d src/selective.d src/sqlite.d src/sync.d src/upload.d src/util.d
    make: dmd: Command not found
    Makefile:29: recipe for target ‘onedrive’ failed
    make: *** [onedrive] Error 127

  2. I am having an issue with the starting onedrive at login. The part right here:

    sudo systemctl –user enable onedrive

    Returns this at the terminal:
    Failed to connect to bus: No such file or directory

    what step should I take next?

  3. Is possible to run multiple client simultaneously? I have 1 personal and 2 bussiness account, is possible to have all 3 synchronized ?

  4. Very informative and descriptive article. It took me a few, but Onedrive is up and running without any issues thanks to your post!!

  5. Hi Damien,
    I’m running into an error while trying to install onedrive
    user:~/onedrive$ make

    cc: No such file or directory
    Error: linker exited with status 255
    Makefile:29: recipe for target ‘onedrive’ failed
    make: *** [onedrive] Error 1

  6. Hi all,

    The git clone command is referring to git clone https://github.com/skilion/onedrive.git which appears to have been abandoned and contains issues that have not been fixed.

    If you wish to use the latest code which contains numerous fixes and enhancements you need clone from here: https://github.com/abraunegg/onedrive

    @Ren – Your issue is fixed in the updated branch – it is a coding defect as to why it does not work
    @Honza – Yes it is, you need 3 separate configuration files / config directories but no issue in doing that.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.

Sponsored Stories