LoginSignup
3
0

More than 3 years have passed since last update.

[GCP] IAP接続をsshコマンドで実施する

Last updated at Posted at 2021-04-06

gcpにてIAPを使用して接続する際、下記のようなコマンドを入力すると思う

gcloud beta compute ssh <hostname> --tunnel-through-iap

これをdry-runで動かすことで、sshコマンドへの渡し方がわかる

/usr/bin/ssh -t -i /home/<user>/.ssh/google_compute_engine -o CheckHostIP=no -o HostKeyAlias=compute.4394459190115035637 -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=/home/<user>/.ssh/google_compute_known_hosts -o ProxyCommand /usr/bin/python3 -S /opt/google-cloud-sdk/lib/gcloud.py beta compute start-iap-tunnel bastion %p --listen-on-stdin --project=<project> --zone=<zone> --verbosity=warning -o ProxyUseFdpass=no <user>@compute.4394459190115035637

不要な設定など取り除き、configに落とし込む

~/.ssh/config
host <hostname>
  user <user>
  hostname <hostname>
  identityfile ~/.ssh/google_compute_engine
  CheckHostIP no
  IdentitiesOnly yes
  ProxyUseFdpass no
  UserKnownHostsFile=~/.ssh/google_compute_known_hosts
  ProxyCommand gcloud beta compute start-iap-tunnel %h %p --listen-on-stdin --project=<project> --zone=<zone> --verbosity=warning --account=<account>

<>内は適宜変更してください

3
0
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
3
0