11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ローカルマシン からCloud Shellに接続(ssh, scp, mount)する

Last updated at Posted at 2018-10-10

Cloud Shell に ssh 接続する

$ gcloud alpha cloud-shell ssh 

API [cloudshell.googleapis.com] not enabled on project
Would you like to enable and retry (this will take a
few minutes)? (y/N)?  y //Cloud Shell API をONにする

your_account_name@cloudshell:~ (project_id)$ //ssh接続できた

config を設定しておくと便利

$ gcloud config set project [your_project_id]
$ gcloud config set account hogehoge@gmail.com
$ gcloud config list

[core]
account = hogehoge@gmail.com
disable_usage_reporting = False
project = [your_project_id]

Your active configuration is: [your_project_id]

//configを複数持つことも可能
$ gcloud config configurations list
NAME         IS_ACTIVE  ACCOUNT                  PROJECT        DEFAULT_ZONE  DEFAULT_REGION
default      False      hogehoge@gmail.com  [your_project_id_1]
flatfish-jp  True       hogehoge@gmail.com  [your_project_id_2]

ssh接続はせずにコマンドの実行

$gcloud alpha cloud-shell ssh --command=ls
fileA
fileB
fileC

scpコマンドでファイルをアップロード

$gcloud alpha cloud-shell scp localhost:`pwd`/filea cloudshell:~/

$gcloud alpha cloud-shell ssh --command=ls
filea

scpコマンドでファイルをダウンロード

$gcloud alpha cloud-shell scp cloudshell:~/filea  localhost:`pwd`/

$ls
filea

マウント

sshfsインストールしていることが前提
参考: Macでsshfsを使ってローカルからリモートのファイルを触る

$ mkdri testdir
$ gcloud alpha cloud-shell get-mount-command testdir/
sshfs hogehoge@hogehoge: testdir/ -p 6000 -oIdentityFile=$HOME/.ssh/google_compute_engine -oStrictHostKeyChecking=no

//出て結果をそのまま実行すると testdir/ にマウントされる
$ sshfs hogehoge@hogehoge: testdir/ -p 6000 -oIdentityFile=$HOME/.ssh/google_compute_engine -oStrictHostKeyChecking=no

//マウント解除
$ diskutil unmount testdir
11
13
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
11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?