In this article we’ll consider how to connect free cloud storages like Google Drive or OneDrive in Linux CentOS. You can use them to backup data or just to exchange files between your hosts. For example, you can install a cloud storage client in your Windows desktop, upload files to it and automatically get access to shared files from Linux (or vice versa).
Often the webmasters or web developers don’t know that they can use cloud storages if there is not enough free space on a virtual machine or in a container. In my work I recommend users to connect cloud storages to store some files they don’t need often or to backup a website or MySQL/MariaDB databases there.
In this article we’ll consider how to connect the most popular free storages (OneDrive and Google Drive), to a host running Linux CentOS 7.
How to Mount Google Drive as a Storage in Linux?
Let’s take a look at how to connect Google Drive on Linux CentOS 7. The installation is very fast and simple.
Download Google Drive client using the command:
# wget -O drive https://drive.google.com/uc?id=0B3X9GlR6EmbnMHBMVWtKaEZXdDg
Move the file to /usr/sbin:
# mv drive /usr/sbin/drive
Change file permissions:
# chmod +x /usr/sbin/drive
Google Drive installation is over, you only have to start the client and sign in:
Go to the following link in your browser:
Enter verification code:
Copy the link and open it in a browser on your PC and allow access to your Google account.
Then you will get a link to enter in your Linux console:
Google Drive is connected, but it does not use the WebDav protocol (it is not supported). So, you do not see it either as a separate file system or a local directory. You can address Google Drive through the
You can view the files in your Google Drive using the command:
# drive list
Files are displayed as a table having four columns:
Id– a unique file code
Title– a file name
Size– a file size
Created– a date of creation
To test it, we can create a file and upload it to g.drive:
touch testdrive.txt && drive upload --file testdrive.txt
The file has been created, you can see it in the console. Also make sure that the file has appeared in Google Drive web interface:
So we have connected Google Drive to our Linux server. I like Google Drive since you don’t have to do anything on the server to mount the cloud storage after each server restart. You can restart your server as many times as necessary and Google Drive will be connected automatically. However, there are some disadvantages: you don’t see the cloud storage as a separate directory on the server and cannot manage files on the file system level or using the usual bash commands.
Mounting OneDrive in Linux
OneDrive is a cloud storage by Microsoft. By default it is available for all Windows 10 users with the linked account (5GB are offered in OneDrive for free). Our task is to connect OneDrive in CentOS 7. During the configuration I came across a lot of problems that can be solved after some experimenting. You will only have to read the instructions and follow these steps on your server.
First of all, sign up using this link: https://onedrive.live.com
Then install the required packages in Linux CentOS using yum:
# yum groupinstall 'Development Tools' -y
# yum install libcurl-devel -y
# yum install sqlite-devel -y
Then install the programming language D(dlang). It will be required to install the OneDrive client:
# curl -fsS https://dlang.org/install.sh | bash -s dmd
To run D(dlang), enter this command:
source ~/dlang/dmd-2.088.0/activate — in your case, the dmd version may differ, so specify the one you have.
After running dlang, install OneDrive client:
git clone https://github.com/abraunegg/onedrive.git
make clean; make;
sudo make install
The installation is over, then you have to activate the client in OneDrive web version. Run the command:
The system will show you the link you must enter in your browser. Click Allow in the web form of the access request. Then the link will change to the unique one containing the code you will have to enter in your Linux console.
Authorize this app visiting: https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=xxxxxx Enter the response uri https://login.microsoftonline.com/common/oauth2/nativeclient?code=xxxxxx
After the link confirmation, I can synchronize with OneDrive cloud storage:
# onedrive --synchronize
Initializing the Synchronization Engine ... Syncing changes from OneDrive ... Processing 6 changes Creating directory: Pictures Creating directory: Documents Downloading file Getting started with OneDrive.pdf ... done. Creating directory: backup Downloading file backup/test.txt ... done.
By default, /root/OneDrive directory containing all folders of my cloud storage has been created on my Linux host.
# ls -la /root/OneDrive/
To test it, I created a file test2.txt and synchronized the storages:
# onedrive --synchronize
Initializing the Synchronization Engine ... Syncing changes from OneDrive ... Uploading new file ./backup/test2.txt ... done.
The file was uploaded to the OneDrive cloud:
To change the default directory, you must change the
sync_dir parameter in the configuration file and run this command:
# onedrive --synchronize --resync
Initializing the Synchronization Engine ... Syncing changes from OneDrive ... Processing 12 changes
After restarting the server, OneDrive client is started automatically and you don’t need to sign in again.
In the next article, we’ll consider how to use cloud storages to backup data from a Linux server.