LoginSignup
3
4

More than 5 years have passed since last update.

[GoogleComputeEngine]gcloud compute sshを使わずにローカルマシンからSSHでログインできるようにする。

Last updated at Posted at 2016-11-10

前提条件

gcloud compute sshを使わない前提でご説明します。

macでやってます。windowsの場合はputtygenなどで鍵の作成を行なってください。
予めGCEにてインスタンスを作成しておき、外部IPをメモしてください。

スクリーンショット 2016-11-10 16.39.03.png

やり方

ログインするためのsshキーの作成

ログインを行うためのSSHキーを作成します。
パスフレーズはできるだけ入れたほうがいいかもです

rache:.ssh rache$ ssh-keygen -t rsa -b 4096 -C "自分のメールアドレス"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/rache/.ssh/id_rsa): /Users/rache/.ssh/id_rsa_develop
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

rache:.ssh rache$ ls
id_rsa_develop id_rsa_develop.pub
known_hosts
rache:.ssh tokuhiro$ cat id_rsa_develop.pub 

公開鍵の登録

表示された公開鍵(id_rsa_develop.pub)を「ComputeEngine→メタデータ→SSH認証鍵に登録」

スクリーンショット 2016-11-10 16.44.33.png

rache:.ssh rache$ ssh xxx.xxx.xxx.xxx -i id_rsa_develop
Are you sure you want to continue connecting (yes/no)? yes
[rache@develop ~]$ 

これで入れます。

ちょい補足

以下ファイルを加えると、鍵の管理が複雑にならなくていいかもです。

~/.ssh/config
Host xxx.xxx.xxx.xxx
  HostName xxx.xxx.xxx.xxx
  User rache
  Port 22
  IdentityFile ~/.ssh/id_rsa_develop
  TCPKeepAlive yes
  IdentitiesOnly yes

 特定のインスタンスのみ入れるようにしたい場合

上記の設定だと、作成したプロジェクト全てにSSHで入れるようになってしまいます。
特定のインスタンスのみに限って入れるようにしたい場合は、
「VMインスタンス」からインスタンスの編集を行い、「SSH認証鍵」欄にて
作成した「id_rsa_develop.pub」の内容を貼り付けてください。

スクリーンショット 2016-11-10 16.50.50.png

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