[OpenSource] rclone - Google Drive 연결하기 - Linux

클라우드 스토리지 서비스하는 벤더들이 있다.
Aws의 S3, 구글드라이브, Dropbox 등등

본인이 직접 스토리지를 관리하는 방법보다 온라인으로 파일을 저장하여 언제든 물리적인 공간을 확보하고 장소의 영향 없이 온라인으로 상시로 연결할 수 있어서 클라우드 스토리지를 사용하는데 이 중에 리눅스로 rclone 오픈소스를 사용하여 다뤄보고자 한다.

그리고 이 글의 내용으로 구글 드라이브 대상으로 사용할 것이다.


rclone 설치

범용 설치

curl https://rclone.org/install.sh | sudo bash
rclone --version

데비안 계열

apt install -y rclone
rclone --version

rclone --verison키워드를 입력한 경우 시스템의 버전이 상세히 출력한다.

root@14ZB990:~# rclone --version
rclone v1.60.1-DEV
- os/version: debian 12.9 (64 bit)
- os/kernel: 6.8.12-7-pve (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.19.8
- go/linking: dynamic
- go/tags: none

Google API 발급하기

rclone 사용 시 Google의 API 키를 요구한다.

Google API Key

  • OAuth 클라이언트 ID (client_id)
  • OAuth 클라이언트 보관 비밀번호 (client_secret)

rclone 설정

rclone 설정 전에 리눅스 일반 사용자로 로그인한다.

rclone config
kiioio@14ZB990:~$ rclone config
2025/05/19 16:57:44 NOTICE: Config file "/home/kiioio/.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

n/s/q> 새로운 연결 시작으로 n 입력 후 엔터

Enter name for new remote.
name> gdrive

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ (fichier)
 2 / Akamai NetStorage
   \ (netstorage)
 3 / Alias for an existing remote
   \ (alias)
 4 / Amazon Drive
   \ (amazon cloud drive)
...
18 / Google Drive
   \ (drive)
...
Storage> drive

name>
새로운 연결 이름을 지정한다. 본인은 gdrive 이름으로 지었다.

Stroage>
스토리지를 어떤 것인지 물어본다 본인은 구글 드라이브 사용으로 drive 명령어로 입력하였다.

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>

client_id> ...
구글 API 클라이언트 키를 입력한다.

Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret>

client_secret> ...
구글 API 시크릿 키를 입력한다.

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>

scope> drive.readonly
rclone 구글 드라이브 API 용도를 선택한다. 1번은 모든 권한을 사용할 수 있다.
본인은 읽기 권한만 필요하기에 2번을 선택한다.

Option service_account_file.
Service Account Credentials JSON file path.
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.
Enter a value. Press Enter to leave empty.
service_account_file>

service_account_file>
구글 SA 파일이 있는지 물어본다. 없는 경우 비어두도록 한다.
SA 파일은 API 발급 시 제공된 JSON 파일이다.

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

기본 값으로 엔터를 클릭한다.

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>

기본 값으로 엔터를 클릭한다.
이제 rclone 서비스가 실행되어 브라우져 url 주소를 줄 것이다.

2025/05/19 17:58:52 NOTICE: Make sure your Redirect URL is set to "http://127.0.0.1:53682/" in your custom config.
2025/05/19 17:58:52 NOTICE: If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=Y3sHtR6M
2025/05/19 17:58:52 NOTICE: Log in and authorize rclone for access
2025/05/19 17:58:52 NOTICE: Waiting for code...

브라우져 인증 확인이다.
해당 url 주소를 입력하여 구글 이메일을 로그인한다.

URL 주소를 받지 못하였다면 rclone authorize "drive" 입력하여 다시 요청할 수 있다.


트러블 슈팅

  • API 꺼져있음
Failed to create file system for "gdrive:/": couldn't find root directory ID: googleapi: Error 403: Google Drive API has not been used in project 625790428836 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/drive.googleapis.com/overview?project=625790428836 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
Details:
[
  {
    "@type": "type.googleapis.com/google.rpc.ErrorInfo",
    "domain": "googleapis.com",
    "metadata": {
      "activationUrl": "https://console.developers.google.com/apis/api/drive.googleapis.com/overview?project=625790428836",
      "consumer": "projects/625790428836",
      "containerInfo": "625790428836",
      "service": "drive.googleapis.com",
      "serviceTitle": "Google Drive API"
    },
    "reason": "SERVICE_DISABLED"
  },

위와 같이 오류 문구가 출력되고 이유(reason)를 살펴보면 SERVICE_DISABLED 표시되어 있다. 아래 링크로 들어가 활성화한다.

Google Cloud Platform
Google Cloud Platform lets you build, deploy, and scale applications, websites, and services on the same infrastructure as Google.