KI 0589 How do I use OneDrive on Linux?
Installation
All machines should have the repo for onedrive added so installing onedrive is easy. In a terminal window, run the command:sudo apt install onedrive
Configuration
Before you start the program, it's a good idea to make some preparations. Find OneDrive in the browser and see what you have there. It is not certain that you want to synchronize everything to the machine. There are many ways to use onedrive and there is good documentation to be found here: https://github.com/abraunegg/onedrive/blob/master/docs/USAGE.mdThe configuration is done in the folder ~/.config/onedrive. It must be made:
mkdir ~/.config/onedrive
A configuration file with default settings can be found at https://github.com/abraunegg/onedrive/blob/master/config, and may be downloaded to ~/.config/onedrive to simplify the configuration process. If not, create the file config in ~/.config/onedrive.
It is recommended that you at least change the configuration to ignore "dotfiles". Edit the configuration file and set skip_dotfiles to true:
# debug_https = "false"
skip_dotfiles = "true"
# skip_size = "1000"
We recommend configuring onedrive to use one of these two methods:
- Specify what to synchronize
- Specify what not to synchronize
1. Specify what to synchronize
By specifying what is to be synchronized, you practically choose that only what you specify is synchronized and everything else is ignored. This is an advantage if you have a lot lying around in OneDrive and/or on the disk that you do not need to synchronize. Edit ~/.config/onedrive/config such that it contains the following lines:skip_file = "~*|.~*|*.tmp|*.exe|*.lnk"
skip_dotfiles = "true"
Then, create a file in the configuration folder called sync_list and specify in it what you want to be synchronized. Documentation can be found here: https://github.com/abraunegg/onedrive/blob/master/docs/USAGE.md#performing-a-selective-sync-via-sync_list-file
All lines in this file are files or folders relative to sync_dir. Examples:
/Documents/ synchronizes the Documents folder in the root folder
Documents/ synchronizes all folders named Documents
Documents synchronizes all files and folders named Documents
work/proj* synchronizes all files or folders that start with proj and are located in a folder called work
An example of a sync_list is:
/Desktop/
/Documents/
/Music/
/Pictures/
/Public/
/Templates/
/Videos/
2. Specify what should not be synchronized
By specifying what should not be synchronized, you have fairly good control over what will be synchronized to begin with. Other files or folders that are added and that are not mentioned in the exception lists will then be automatically synchronized. To synchronize only parts of OneDrive, we edit ~/.config/onedrive/config as follows:skip_dotfiles = “true”
# Add what should not be synchronized using skip_file and skip_dir. One can list several things by using '|' between them or/and specifying skip_file and skip_dir several times. Example:
skip_file = “*.exe|*.lnk”
skip_file = “*.tmp”
skip_dir = “Microsoft*|Favorites”
skip_dir = “Downloads”
# Specify as much or as little as you need. skip_file/skip_dir skips everything it finds both in sync_dir and on OneDrive, so what is specified as an exception will not be synchronized to or from.
Choose a folder to synchronize to
You can choose for yourself which folder you want to use for synchronization with OneDrive by defining a sync_dir in ~/.config/onedrive/config. sync_dir = "~/OneDrive" is the default option, but you can also use sync_dir = "~/" if you want to synchronize the home folder itself. Go through what you have stored and optionally make an exclusion or inclusion list as shown in the previous sections. It is a good idea to make sure that skip_dotfiles = “true” is defined.
Start the program and authenticate
When you are confident about the configuration, you can start onedrive with the command "onedrive":[user@hostname ~]$ onedrive
Authorize this app visiting:
https://.....
Enter the response uri:
Hold ctrl and click on the link with the mouse and it will take you to the browser where you will log in. After successfully signing in, you will get an empty window. Copy the address and paste it into the terminal window:
[user@hostname ~]$onedrive
Authorize this app visiting:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=22c49a0d-d21c-4792-aed1-8f163c982546&scope=Files.ReadWrite%20Files.ReadWrite.all%20Sites.ReadWrite.All%20offline_access&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient
Enter the response uri: https://login.microsoftonline.com/common/oauth2/nativeclient?code=<redacted>
Application has been successfully authorized, however no additional command switches were provided.
Please use 'onedrive --help' for further assistance in regards to running this application.
You have now authenticated the program. You can test your configuration by running
onedrive --display-config
Check that it looks good. Afterwards, you can run a "dry-run" to see what the program wants to do:
onedrive --synchronize --verbose --dry-run
If this looks good, start the synchronization with
onedrive --synchronize
Run onedrive as a system command that starts automatically
To make onedrive run automatically, you can runsystemctl enable --user onedrive
systemctl start --user onedrive
Now, onedrive will start automatically and run in the background. To check for any errors, you can check its status:
systemctl status --user onedrive
journalctl --user-unit=onedrive -f -q
Resynchronize after changes
If you make changes to config, sync_list and/or business_shared_folder, you must resynchronize. Stop the service and run onedrive with --resync:systemctl stop --user onedrive
onedrive --resync --synchronize
systemctl start --user onedrive
Notes
OneDrive on Linux has limited functionality. In particular, collaboration will not work as you are used to from Windows/Mac. If you need this from OneDrive on Linux, we recommend using OneDrive in a browser. For file synchronization with OneDrive, both options mentioned above will work.Otherwise, see information about collaboration in OneDrive on KI 0620