Skip to content

Instantly share code, notes, and snippets.

@flatfisher
Last active May 24, 2021 11:26
Show Gist options
  • Save flatfisher/ccbd3dd723371f1805b59196cba5432c to your computer and use it in GitHub Desktop.
Save flatfisher/ccbd3dd723371f1805b59196cba5432c to your computer and use it in GitHub Desktop.
ローカルマシン からCloud Shellに接続(ssh, scp, mount)する ref: https://qiita.com/flatfisher/items/1d6ffe94787b77e3f2ee
$ 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接続できた
$ 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]
$gcloud alpha cloud-shell ssh --command=ls
fileA
fileB
fileC
$gcloud alpha cloud-shell scp localhost:`pwd`/filea cloudshell:~/
$gcloud alpha cloud-shell ssh --command=ls
filea
$gcloud alpha cloud-shell scp cloudshell:~/filea localhost:`pwd`/
$ls
filea
$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment