LinuxでGoogleDriveをマウントする

UbuntuでGoogleドライブにアクセスしようとして、cd /mnt/g って打ったのですがcdできませんでした。

$ cd /mnt/g
-bash: cd: /mnt/g: No such file or directory

cd /mnt/c ならディレクトリを移動できます。

~$ cd /mnt/c

LinuxだとGドライブをマウントできていないようです。

そこで、LinuxでGoogleDriveをmountするために rclone を使ってみます。

Linuxにrcloneをインストールする

rcloneの公式ドキュメントを見ると、インストールのためにコマンドをいろいろ打っていますが、apt install rclone でインストールしました。
https://rclone.org/install/#linux

Ubuntuを立ち上げ、rcloneをインストールします。

$ sudo apt install rclone

rcloneのバージョンを確認します。

$ rclone version
rclone v1.60.1-DEV

rcloneにGoogleDriveの設定をする

Ubuntuで rclone config と打つとマウントするディレクトリの設定ができます。rclone.confが見つからないので対話型で設定する流れになってます。

$ rclone config
2025/07/31 15:35:56 NOTICE: Config file "/home/xxx/.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 と打ち New remote を選択すると、新しいマウント先の設定を始めます。

n/s/q> n

Enter name for new remote.

マウント先の名前を決めます。今回は gdrive と入力しました。

Enter name for new remote.
name> gdrive

名前を決めてEnterを押すと、ストレージタイプがずらっと表示されます。

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.

ストレージタイプの一部を抜粋しています。GoogleDriveは18番なので、18 と入力します。

17 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
18 / Google Drive
   \ (drive)
19 / Google Photos
   \ (google photos)

Storage> 18

クライアントIDを入力するように求められます。ここは空欄でEnterでもいいと書かれていますが、空欄だとパフォーマンスの低い内部キーになるようです。パフォーマンスとはGoogleDriveに対して何か処理するときの速度です。

Option client_id.
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 value. Press Enter to leave empty.
client_id>

下記サイトを見てクライアントIDを決めようと思います。
https://rclone.org/drive/#making-your-own-client-id

Google API コンソールで、GoogleDriveにアクセスするためのAPIキーを作るイメージです。

以下のところクリックすると client_id の作成を行えます。

client_idclient_secret はGoogleのサイトで取得したものを入力します。

client_id> Googleアカウントで作成したIDを入力
client_secret> その時のクライアントシークレットを入力

scope は 1 / Full access を選択しました。

Option scope.
Scope that rclone should use when requesting access from drive.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 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>

service_account_file を要求されます。サービス アカウントの資格情報 JSON ファイルのパスです。ここは空白のままにしました。

Option service_account_file.
Service Account Credentials JSON file path.
Leave blank normally.
Needed only if you want use SA instead of interactive login.
service_account_file> 何も入力せずにEnter

advanced config を聞かれますが、n を選択しました。

Edit advanced config?
y) Yes
n) No (default)
y/n>

auto config を聞かれるので y を入力しました。

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>

ここで認証作業が発生します。認証が完了すると、以下のように表示されます。

NOTICE: Log in and authorize rclone for access
NOTICE: Waiting for code...
NOTICE: Got code

共有ドライブか聞かれますが、n と入力します。

Configure this as a Shared Drive (Team Drive)?

y) Yes
n) No (default)
y/n>

最後に保存するか聞かれるので、y を入力します。

Configuration complete.

Keep this "gdrive" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> yを入力

以上で、対話形式の設定作業は終了です。Remote先の一覧が表示されます。q を入力して対話を終わらせます。

Current remotes:

Name                 Type
====                 ====
gdrive               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>

LinuxでGoogleDriveをマウントする

準備はできたので Ubuntu を立ち上げ、GoogleDrive をマウントします。

rclone mount の仕様は以下のようになっています。
rclone mount ドキュメント
https://rclone.org/commands/rclone_mount/

rclone mount remote:path/to/files /path/to/local/mount

remote:path/to/files がrcloneで設定したRemote名です。今回の gdrive になります。

/path/to/local/mount はローカルの空のディレクトリです。

まず、PCローカルに空のディレクトリを作成します。そして、マウントしてみましたがエラーになりました。

$ sudo mkdir /mnt/g
$ rclone mount gdrive: /mnt/g &

エラーは以下のような文言でした。

mount helper error: fusermount: user has no write access to mountpoint /mnt/g
Fatal error: failed to mount FUSE fs: fusermount: exit status 1

パーミッションの問題とのことでしたので、パーミッションを見てみます。

$ ls -ld /mnt/g
drwxr-xr-x 2 root root 4096 Aug  2 11:11 /mnt/g

/mnt/g のパーミッションを変更します。

パーミッションを変更する
$ sudo chown $USER:$USER /mnt/g
パーミッションを確認する
$ ls -ld /mnt/g
drwxr-xr-x 2 xxx xxx 4096 Aug  2 11:11 /mnt/g

再度マウントすると、成功しました。

$ rclone mount gdrive: /mnt/g &

cd /mnt/g して ls すると GoogleDrive の中身が見えました。

$ cd /mnt/g
/mnt/g$ ls

rcloneのコマンド

rcloneのコマンド一覧です。アンマウントは無いです。

$ rclone help
Usage:
  rclone [flags]
  rclone [command]

Available Commands:
  about           Get quota information from the remote.
  authorize       Remote authorization.
  backend         Run a backend-specific command.
  bisync          Perform bidirectional synchronization between two paths.
  cat             Concatenates any files and sends them to stdout.
  check           Checks the files in the source and destination match.
  checksum        Checks the files in the source against a SUM file.
  cleanup         Clean up the remote if possible.
  completion      Generate the autocompletion script for the specified shell
  config          Enter an interactive configuration session.
  copy            Copy files from source to dest, skipping identical files.
  copyto          Copy files from source to dest, skipping identical files.
  copyurl         Copy url content to dest.
  cryptcheck      Cryptcheck checks the integrity of a crypted remote.
  cryptdecode     Cryptdecode returns unencrypted file names.
  dedupe          Interactively find duplicate filenames and delete/rename them.
  delete          Remove the files in path.
  deletefile      Remove a single file from remote.
  genautocomplete Output completion script for a given shell.
  gendocs         Output markdown docs for rclone to the directory supplied.
  hashsum         Produces a hashsum file for all the objects in the path.
  help            Show help for rclone commands, flags and backends.
  link            Generate public link to file/folder.
  listremotes     List all the remotes in the config file.
  ls              List the objects in the path with size and path.
  lsd             List all directories/containers/buckets in the path.
  lsf             List directories and objects in remote:path formatted for parsing.
  lsjson          List directories and objects in the path in JSON format.
  lsl             List the objects in path with modification time, size and path.
  md5sum          Produces an md5sum file for all the objects in the path.
  mkdir           Make the path if it doesn't already exist.
  mount           Mount the remote as file system on a mountpoint.
  move            Move files from source to dest.
  moveto          Move file or directory from source to dest.
  ncdu            Explore a remote with a text based user interface.
  obscure         Obscure password for use in the rclone config file.
  purge           Remove the path and all of its contents.
  rc              Run a command against a running rclone.
  rcat            Copies standard input to file on remote.
  rcd             Run rclone listening to remote control commands only.
  rmdir           Remove the empty directory at path.
  rmdirs          Remove empty directories under the path.
  selfupdate      Update the rclone binary.
  serve           Serve a remote over a protocol.
  settier         Changes storage class/tier of objects in remote.
  sha1sum         Produces an sha1sum file for all the objects in the path.
  size            Prints the total size and number of objects in remote:path.
  sync            Make source and dest identical, modifying destination only.
  test            Run a test command
  touch           Create new file or change file modification time.
  tree            List the contents of the remote in a tree like fashion.
  version         Show the version number.

Use "rclone [command] --help" for more information about a command.
Use "rclone help flags" for to see the global flags.
Use "rclone help backends" for a list of supported services.

コマンド実行例をいくつか。

マウント

gdrive は rclone で設定したremote。/mnt/g は空のディレクトリ。

$ rclone mount gdrive: /mnt/g &

マウント先のディレクトリを表示

$ rclone lsd gdrive:

rcloneのremoteを削除する

Ubuntu上で rclone config と打つと、何をするか聞かれるので Delete remote を選択するとremoteを削除できます。

$ rclone config

Current remotes:

Name                 Type
====                 ====
gdrive               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> dを選択する

削除したいマウント先の番号を入力すると、remoteの削除が完了します。

e/n/d/r/c/s/q> d

Select remote.
Choose a number from below, or type in an existing value.
 1 > gdrive
remote> 1を選択する