LoginSignup
6
2

More than 3 years have passed since last update.

GCPでgcloudコマンドを利用する

Posted at

はじめに

GCPのCompute EngineでCentOS8のサーバを作成した。
gcloudコマンドはデフォルトでインストールされているらしく、すぐに利用できた。
と思ったが、以下のコマンドでスナップショット一覧を確認すると怒られた…

$ gcloud compute snapshots list
ERROR: (gcloud.compute.snapshots.list) Some requests did not succeed:
 - Insufficient Permission: Request had insufficient authentication scopes.

Cloud SDK ツールの承認

詳細は以下のURLに記載がありますが、Cloud SDKツールを承認させる必要があるとのこと。

gcloud auth loginコマンドを実行

$ gcloud auth login

You are running on a Google Compute Engine virtual machine.
It is recommended that you use service accounts for authentication.

You can run:

  $ gcloud config set account `ACCOUNT`

to switch accounts if necessary.

Your credentials may be visible to others with access to this
virtual machine. Are you sure you want to authenticate with
your personal account?

Do you want to continue (Y/n)?  Y

つらつらと表示されるが、続けるべくYを押下。

Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?code_challenge=jNfasfasforuaaf87anfda17nagagadfasdo&prompt=select_account&code_challenge_method=S256&access_type=offline&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=44456445.5533453.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth

するとこんな感じのURLが表示されるので、ブラウザで表示してみる。
image.png

googleアカウントのメールアドレス、パスワードでログイン。
すると以下の表示になるので、許可を押下。

image.png

コードが表示されるので、コピーします。
image.png

で、ターミナルにもどりコピーしたコードを入力します。

Enter verification code: ここにコード入力

これで、Cloud SDKツールの承認が終わりです。

You are now logged in as [someone@example.jp].
Your current project is [yourproject-0000000].  You can change this setting by running:
  $ gcloud config set project PROJECT_ID

gcloudコマンドを試す

実際に試してみよう。

$ gcloud compute snapshots list 
NAME                       DISK_SIZE_GB  SRC_DISK                         STATUS
sample-snapshot-20190611   100           asia-northeast1-b/disks/server2  READY
webserver2-snap-20191203   100           asia-northeast1-b/disks/server2  READY

こんな感じでGCPのプロジェクトに対して、gcloudコマンドが使えるようになりました。

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2