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
- 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
- Debian/Ubuntu:
- Start the configuration wizard – Run
rclone configin the terminal. This will launch an interactive setup. - Create a new remote – When prompted, type
n(for new remote) and press Enter. - Name the remote – Enter a descriptive name like
onedrive(or any name you prefer) and press Enter. - 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. - Select the OneDrive account type – When asked, choose
OneDrive Personalfor personal accounts orOneDrive Businessfor work/school accounts. Most home users pick Personal. - Skip advanced configuration – When asked about advanced config, type
nand press Enter. - Use auto config – When asked if you want to use auto config, type
yand press Enter. This will open a browser window for you to log in to your Microsoft account and grant rclone permission. - 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.
- If auto config fails – If no browser opens or you’re on a headless server, choose
nfor 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. - Confirm the remote – After authentication, rclone will ask if the remote is OK. Type
yto confirm and save the configuration. Then typeqto quit the config wizard. - Test the connection – Run
rclone lsd onedrive:(replaceonedrivewith your remote name). You should see a list of folders from your OneDrive. If you see an error, check the troubleshooting section below. - Create a local sync folder – Choose a directory on your Linux system, e.g.,
mkdir ~/OneDrive - 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. - Set up two-way sync (optional but recommended) – For continuous syncing in both directions, use the
rclone bisynccommand. First, create an empty local folder, then run:rclone bisync onedrive: ~/OneDrive --create-empty-src-dirs --resync. The--resyncflag is needed only the first time. - Automate syncing with cron – To sync regularly, edit your crontab with
crontab -eand 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 syncinstead ofbisyncfor two-way sync –syncmakes the destination identical to the source, deleting files on the destination that aren’t on the source. If you want changes in both directions, usebisync. - 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 lsdfirst 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
~/OneDriveto avoid clutter. - Check bandwidth usage – If you have a data cap, consider limiting transfer speed with the
--bwlimitflag, e.g.,--bwlimit 2Mfor 2 MB/s. - Exclude large or unnecessary files – Use the
--excludeflag to skip certain file types or folders, e.g.,--exclude "*.tmp". - Keep rclone updated – Run
sudo rclone selfupdateperiodically 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.logto 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
nfor 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 (runsudo ntpdate pool.ntp.orgor 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 onedriveand 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--resyncon the first run. - Permission denied errors – Make sure you have read/write permissions on the local folder. Try
chmod 700 ~/OneDriveor 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
--checkersand--transfersflags 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
- Google Desktop Search Widget on Windows 11
- How to Build a Computer Stand (Saturday Workshop)
- Customize Touch Keyboard Themes in Windows 11
- Excel Pivot Table: Change Multiple Field Settings
- WhatsApp: How to Block Unknown Numbers
- How to Exit Vi in Linux: A Simple Guide