How to access Google Drive on Linux Server
Google Drive which is a cloud storage service from Google officially only provides client applications for Windows, macOS, Android, and iOS. While the Linux version is not officially available, but some developers out there develop client applications for Google Drive, one of which is rclone.
0.About rclone
rclone is a command line based application that functions to synchronize files and directories from / to various cloud storage services or file server / storage protocols.
Cloud storage services supported by rclone are Amazon Drive, Amazon S3, Box, Ceph, DigitalOcean Spaces, Dropbox, Google Cloud Storage, Google Drive, Nextcloud, ownCloud, FTP, SFTP, and many more.
1.Install rclone
Download and extract compiled rclone.
1 2 3 | curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip unzip rclone-current-linux-amd64.zip cd rclone-*-linux-amd64 |
Copy rclone.
1 2 3 | sudo cp rclone /usr/bin/ sudo chown root:root /usr/bin/rclone sudo chmod 755 /usr/bin/rclone |
Install the rclone manual.
1 2 3 | sudo mkdir -p /usr/local/share/man/man1 sudo cp rclone.1 /usr/local/share/man/man1/ sudo mandb |
Test the results of installing rclone by displaying the version number.
1 2 3 4 5 | rclone version rclone v1.48.0 - os/arch: linux/amd64 - go version: go1.12.6 |
rclone manual.
1 | man rclone |
or you can also read the official documentation on the rclone website.
2.rclone Configuration
Next do the rclone configuration, add cloud storage that you want to connect to the Linux server.
Run the rclone config command, answer n to make a new connection to cloud storage.
1 2 3 4 5 6 7 8 | rclone config 2019/07/17 13:28:01 NOTICE: Config file "/home/ubuntu/.config/rclone/rclone.conf" not found - using defaults No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n |
Give the name of the connection.
1 | name> driveku |
Enter number 12 for Google Drive.
1 2 3 4 5 6 7 8 9 | ... 12 / Google Drive \ "drive" 13 / Hubic \ "hubic" 14 / JottaCloud \ "jottacloud" ... Storage> 12 |
Enter.
1 2 3 4 5 6 | Google Application Client Id Setting your own is recommended. See https://rclone.org/drive/#making-your-own-client-id for how to create your own. If you leave this blank, it will use an internal key which is low performance. Enter a string value. Press Enter for the default (""). client_id> |
Enter.
1 2 3 4 | Google Application Client Secret Setting your own is recommended. Enter a string value. Press Enter for the default (""). client_secret> |
Enter the number 1 to be able to full access the Google Drive.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | Scope that rclone should use when requesting access from drive. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value 1 / Full access all files, excluding Application Data Folder. \ "drive" 2 / Read-only access to file metadata and file contents. \ "drive.readonly" / Access to files created by rclone only. 3 | These are visible in the drive website. | File authorization is revoked when the user deauthorizes the app. \ "drive.file" / Allows read and write access to the Application Data folder. 4 | This is not visible in the drive website. \ "drive.appfolder" / Allows read-only access to file metadata but 5 | does not allow any access to read or download file content. \ "drive.metadata.readonly" scope> 1 |
The directory or subdirectory in Google Drive that you want to be the root folder. No need to fill in if you want to make the root folder in Google Drive the root folder, press enter.
1 2 3 4 5 | ID of the root folder Leave blank normally. Fill in to access "Computers" folders. (see docs). Enter a string value. Press Enter for the default (""). root_folder_id> |
Enter.
1 2 3 4 5 | Service Account Credentials JSON file path Leave blank normally. Needed only if you want use SA instead of interactive login. Enter a string value. Press Enter for the default (""). service_account_file> |
Edit advanced config, answer n.
1 2 3 4 | Edit advanced config? (y/n) y) Yes n) No y/n> n |
Use auto config?, answer n.
1 2 3 4 5 6 7 | Remote config Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machine y) Yes n) No y/n> n |
Browse the link that appears, log in to your Google Drive account, then allow rclone to access the account, and copy the code that appears to paste in the Enter verification code.
1 2 3 | If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815644.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=a173926604e561815a0855074ea6038f Log in and authorize rclone for access Enter verification code> 4/iQGP0AFMXVf3iaaazUsK-hivV-D6PeaSIbuRfRIIdJWiD7RXUQRfdnU |
Configure it as a team drive ? answer n.
1 2 3 4 | Configure this as a team drive? y) Yes n) No y/n> n |
An overview of the configuration is displayed, if you are sure the configuration is correct answer y.
1 2 3 4 5 6 7 8 9 10 | -------------------- [driveku] type = drive scope = drive token = {"access_token":"ya29.GltIBxdJ9BWv9wsbbdckTxXZIRZ7I0WuxJTEqpBhvMx1d-gyvN6aSOxQS2xqs3jU21ws_eayXF_DkRvqHXgF-yZOo6k6YgUl_1O8KHOp9_kIDU5Az0tHFUvDTqgG","token_type":"Bearer","refresh_token":"1/ZkUB4McwvVSG9lOv8iWmt7I3yp9EK6TcwWvO8-HHbtg","expiry":"2019-07-17T14:42:40.738880079Z"} -------------------- y) Yes this is OK e) Edit this remote d) Delete this remote y/e/d> y |
Shown cloud storage connections that have been made before. Answer q to exit rclone configuration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Current remotes: Name Type ==== ==== driveku drive 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 |
3.rclone commands
Next, access Google Drive via rclone by using the commands.
Showing files.
1 | rclone ls driveku: |
Showing directories.
1 | rclone lsd driveku: |
Showing files and directories.
1 | rclone lsf driveku: |
Create directory.
1 | rclone mkdir driveku:Data |
Copy file.
1 | rclone copy hello.txt driveku:Data |
Deleting files, not deleting directories.
1 | rclone delete driveku:Data |
Removes empty directories.
1 | rclone rmdir driveku:Data |
Removes files and directories.
1 | rclone purge driveku:Data |
4.Mount Google Drive on Linux
rclone can mount Google Drive on Linux.
Make a directory on home directory, and mount Google Drive. The rclone mount command below runs with process ID 2952.
1 2 3 4 | mkdir ~/drive rclone mount driveku: ~/drive & [1] 2952 |
Check the contents of the mount ~ / drive directory, if the contents are the same as those in Google Drive.
1 2 3 4 5 6 7 8 9 | ls -l ~/drive drwxrwxr-x 1 ubuntu ubuntu 0 Jul 17 22:25 Data drwxrwxr-x 1 ubuntu ubuntu 0 Jul 17 22:26 Kampus drwxrwxr-x 1 ubuntu ubuntu 0 Jul 17 22:26 Master ls -l ~/drive/Data/ -rw-rw-r-- 1 ubuntu ubuntu 12 Jul 17 22:11 hello.txt |
Test creating a new file in the ~/drive/Kampus directory. Then compare the contents of the mounted directory with those on Google Drive.
1 2 3 4 5 6 7 8 | echo "ini tugas kampus" > ~/drive/Kampus/tugas01.txt ls -l ~/drive/Kampus/ -rw-rw-r-- 1 ubuntu ubuntu 17 Jul 17 22:47 tugas01.txt rclone lsf driveku:Kampus tugas01.txt |
Stop the rclone mount command process located at Process ID 2952.
1 2 3 | kill 2952 [1]+ Done rclone mount driveku: ~/drive |
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin