Connecting Linux Client to OneDrive - Rclone

Software and Prerequisites

Non Linux platforms

See KB0010947—How do I use OneDrive?
For Mac OS X see KB0012595—Configure OneDrive client for MAC OS X

Linux platforms

Rclone https://rclone.org/ is installed on the Physics HPCs and virtual workstations but is available for most Linux distributions including those derived from Ubuntu.

While its possible to connect to OneDrive without a graphical interface (see https://rclone.org/remote_setup/) these instructions assume you have a graphical interface such as Nomachine. This is required for the authentication phase.

Also see https://rclone.org/onedrive/

Walkthrough

gateway 506 % rclone config
Current remotes:

Name                 Type
====                 ====
Aarnet               webdav

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> n
name> onedrive
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / 1Fichier
   \ "fichier"
.... elided ....
26 / Microsoft OneDrive
   \ "onedrive"
.... elided ....

Storage> 26
** See help for onedrive backend at: https://rclone.org/onedrive/ **

OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> 
OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>
Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
   \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
region>
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> y

At this point Firefox (or Google Chrome) should open on the Office365 login page.

office365 login page

Selecting your Work or school account should take your to your Unikey login page

unikey login page

then to the Okta (2FA) page

okta 2FA page

Then you will be asked to authorize Rclone for use by your account.
This should only happen the first time you use Rclone.

If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=c4JKYc2Ei_BU3orkjx_TOg
Log in and authorize rclone for access
Waiting for code...
Got code
Choose a number from below, or type in an existing value
1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)
   \ "url"
 4 / Search for a Sharepoint site
   \ "search"
 5 / Type in driveID (advanced)
   \ "driveid"
 6 / Type in SiteID (advanced)
   \ "siteid"
 7 / Sharepoint server-relative path (advanced, e.g. /teams/hr)
   \ "path"
Your choice> 1
Found 2 drives, please select the one you want to use:
0: OneDrive (business) id=b!.....
1: OneDrive (business) id=b!..... 
Choose drive to use:> 0
Found drive 'root' of type 'business', URL: https://unisyd-my.sharepoint.com/personal/karl_popper_sydney_edu_au/Documents
Is that okay?
y) Yes (default)
n) No
y/n> y
--------------------
[onedrive]
type = onedrive
region = global
token = {"access_token":"....
drive_id = b!.....
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:

Name                 Type
====                 ====
Aarnet               webdav
onedrive             onedrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

Acessing a OneDrive share

Rclone command line tools

Your OneDrive share can now be accessed using Rclone command line tools

# List contents of the share
rclone lsf onedrive:
#
# Display file on OneDrive 
rclone cat onedrive:Letter.txt
#
# Copy file 
rclone copy Example.txt onedrive:
#
# Get help
rclone --help
# ... for a command
rclone copy --help

Mounting OneDrive share on a local directory

More conveniently a OneDrive share can be mounted locally as a user space file system served by the rclone software running in the background.

# Create mount point in $HOME
# Permissions MUST be rwxr-xr-x (0755)
mkdir -m 0755 ~/onedrive
#
# Mount OneDrive share 
# The --gid=`id -g` argument just retrieves your group id
# so that file under ~/onedrive have this group ownership.
# Substitute the numeric value output from id -g if you wish.
# The --daemon switch places rclone in the background.
#
mount --daemon --gid=`id -g` --umask 027 --vfs-cache-mode writes onedrive: ~/onedrive
#
# List contents of share
#
ls ~/onedrive
#
# When finished unmount share
#
fusermount -u ~/onedrive

Valid XHTML 1.0 Transitional