sodcalculator

10 Tech How-To

Sync OneDrive Account on Linux: Step-by-Step

Guide 10-12298 · Updated · Step by step

This guide walks you through connecting your OneDrive account to a Linux system so your cloud files stay in sync with a local folder. You’ll set up the open-source rclone tool, authenticate with Microsoft, and configure automatic syncing. No prior Linux expertise is needed, but you should have sudo access and an active OneDrive account.

What You’ll Need

  • A Linux distribution (Ubuntu, Debian, Fedora, Arch, etc.) with internet access.
  • Sudo or root privileges to install software.
  • Your Microsoft OneDrive credentials (email and password, or app password if two-factor authentication is enabled).
  • A terminal emulator (usually pre-installed).

Step-by-Step

  1. Install rclone – Open a terminal and run the appropriate command for your distribution:
    • Debian/Ubuntu: sudo apt install rclone
    • Fedora: sudo dnf install rclone
    • Arch: sudo pacman -S rclone
    • For other distributions or the latest version, use the official script: curl https://rclone.org/install.sh | sudo bash
  2. Start the configuration wizard – Run rclone config in the terminal. This will launch an interactive setup.
  3. Create a new remote – When prompted, type n (for new remote) and press Enter.
  4. Name the remote – Enter a descriptive name like onedrive (or any name you prefer) and press Enter.
  5. Choose the storage type – Scroll through the list of storage providers until you find Microsoft OneDrive (usually option 25 or similar). Type the number and press Enter.
  6. Select the OneDrive account type – When asked, choose OneDrive Personal for personal accounts or OneDrive Business for work/school accounts. Most home users pick Personal.
  7. Skip advanced configuration – When asked about advanced config, type n and press Enter.
  8. Use auto config – When asked if you want to use auto config, type y and press Enter. This will open a browser window for you to log in to your Microsoft account and grant rclone permission.
  9. Authenticate with Microsoft – Log in with your OneDrive credentials. If you have two-factor authentication, complete that step as well. After granting access, the browser will show a success message, and you can return to the terminal.
  10. If auto config fails – If no browser opens or you’re on a headless server, choose n for auto config. rclone will give you a URL to visit and a code to enter. On another device, open the URL, log in, paste the code, and you’ll receive a verification code to type back into the terminal.
  11. Confirm the remote – After authentication, rclone will ask if the remote is OK. Type y to confirm and save the configuration. Then type q to quit the config wizard.
  12. Test the connection – Run rclone lsd onedrive: (replace onedrive with your remote name). You should see a list of folders from your OneDrive. If you see an error, check the troubleshooting section below.
  13. Create a local sync folder – Choose a directory on your Linux system, e.g., mkdir ~/OneDrive
  14. Perform an initial one-way sync – To download all files from OneDrive to your local folder, run: rclone sync onedrive: ~/OneDrive. This will copy all files from the cloud to your local folder. Warning: This deletes any files in the local folder that are not in OneDrive. Use with care.
  15. Set up two-way sync (optional but recommended) – For continuous syncing in both directions, use the rclone bisync command. First, create an empty local folder, then run: rclone bisync onedrive: ~/OneDrive --create-empty-src-dirs --resync. The --resync flag is needed only the first time.
  16. Automate syncing with cron – To sync regularly, edit your crontab with crontab -e and add a line like this to run every hour: 0 * * * * rclone bisync onedrive: ~/OneDrive --create-empty-src-dirs --max-lock 2m. Adjust the schedule as needed.

Common Mistakes

  • Using rclone sync instead of bisync for two-way sync – sync makes the destination identical to the source, deleting files on the destination that aren’t on the source. If you want changes in both directions, use bisync.
  • Forgetting to include the colon after the remote name – The remote name must be followed by a colon (e.g., onedrive:), otherwise rclone treats it as a local path.
  • Running sync without testing – Always test with rclone lsd first to ensure authentication works.
  • Not handling two-factor authentication properly – If you have 2FA enabled, you may need to create an app password in Microsoft account settings and use that instead of your regular password during authentication.
  • Using the wrong account type – Choosing Personal when you have a Business account (or vice versa) can cause authentication errors.

Tips

  • Use a dedicated local folder – Don’t sync directly to your home directory; use a subfolder like ~/OneDrive to avoid clutter.
  • Check bandwidth usage – If you have a data cap, consider limiting transfer speed with the --bwlimit flag, e.g., --bwlimit 2M for 2 MB/s.
  • Exclude large or unnecessary files – Use the --exclude flag to skip certain file types or folders, e.g., --exclude "*.tmp".
  • Keep rclone updated – Run sudo rclone selfupdate periodically to get the latest features and bug fixes.
  • Use systemd timers instead of cron – For more reliable scheduling, create a systemd service and timer. This is more robust and can be started at boot.
  • Monitor logs – Add --log-file /path/to/rclone.log to your commands to track sync activity and spot errors early.

Troubleshooting

  • Authentication fails – If the browser doesn’t open or the code doesn’t work, try the manual method: choose n for auto config, then visit the provided URL, enter the code, and paste the resulting token back into the terminal. Also ensure your system time is correct (run sudo ntpdate pool.ntp.org or enable NTP).
  • “Failed to query available drives” – This often means you selected the wrong account type (Personal vs Business). Delete the remote with rclone config delete onedrive and re-create it with the correct type.
  • Files not syncing – Check that you’re using the correct remote name and that the local folder exists. Run rclone lsd onedrive: to verify the connection. If using bisync, ensure you ran --resync on the first run.
  • Permission denied errors – Make sure you have read/write permissions on the local folder. Try chmod 700 ~/OneDrive or run the command with sudo (though not recommended for regular use).
  • High CPU usage – If rclone is consuming too much CPU, reduce sync frequency or use the --checkers and --transfers flags to limit parallelism.
  • Conflicts with existing files – When using bisync, if the same file is modified on both sides, rclone will create a conflict copy. Review these files and merge manually.

Frequently Asked Questions

Can I sync multiple OneDrive accounts?

Yes, you can create multiple remotes in rclone config, each with a different name. Then run separate sync commands for each.

Is rclone the only way?

No, there are other tools like onedrive (a CLI client) and insync, but rclone is the most flexible and widely used.

Does rclone work with OneDrive for Business?

Yes, rclone supports both Personal and Business accounts. Just select the correct option during configuration.

How do I stop syncing?

Simply stop the cron job or systemd timer, and kill any running rclone processes with pkill rclone. Your local files remain intact.

Will rclone delete my local files if I remove them from OneDrive?

With sync, yes. With bisync, deletions are propagated only if you use the --delete flag (which is default). To prevent accidental deletion, use --backup-dir to move deleted files to a backup folder.

Can I sync only specific folders?

Yes, use the --include or --exclude flags, or specify a subfolder in the remote path, e.g., onedrive:Documents.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →