Help us understand the problem. What is going on with this article?

gceからgceへパスワードなしでsshで接続する。いつものubuntuで。

More than 3 years have passed since last update.

GCEのVMから同じくGCEにパスワード無しでSSHで接続する。

  • タイトルにubuntuと書いてあるとおりVMはubuntu12.04だが、linuxならきっと他も一緒 +

環境を用意する

  • 今回はどちらもubuntu12.04です
  • ローカルもubuntu(14.04)です。

1.ローカルからgcloud computeで接続元VMに接続する。
 ググればすぐ出ます。

2.接続元VMでrsaのキーを生成する

junk@main:~/.ssh$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/junk/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/junk/.ssh/id_rsa.
Your public key has been saved in /home/junk/.ssh/id_rsa.pub.
The key fingerprint is:
5d:91:44:65:2c:d3:9c:d6:ff:3f:c6:ec:4e:5f:70:12 junk@main
The key's randomart image is:
+--[ RSA 2048]----+
|         =+*o    |
|        . Boo    |
|         o ...E  |
|         . .  .. |
|        S .   o..|
|               +.|
|               .o|
|              oo+|
|              +=+|
+-----------------+

※上記はキーの一部を改変しております。予めご容赦ください。

3.生成されたキー(公開鍵)をコピーする

$ view /home/junk/.ssh/id_rsa.pub

キーファイルの中身は以下のようになってます。
※内容は改変しております。

ssh-rsa AAAAB3NzaC1yc2EBBBBBBAQABAAABAQDRsFM0Xbae/HOeDUAgshIkiIWVeN9AHpB6QXrdrdaChrvHKcy6swrqyvMYDwEFoRgLsE1IGGQoC+BOygNWZyrAmBz8lpjKsG0oWI0byDmf5qWdEyuNOQ3j2fccC3pJ3gNoyQUwDhFkf6I2j/7R0jlvhKPENguUHcSBYfBCtsgt1ePgBfrYFGtSZCM8TGKNM+FSP+dmLwW3I7u/umzT7o3oRBMzaGxMsaOHaFFFzC1vZNddCpsIF3Q8S+U2KlzWeJupoeDA6VqxyLKqQnms8TaBlmc25AaA69ZAbWQgSoFBNPgnukwjTqZzyfFCHBSNw7PT4gGVCzW+tyj0iXdU7JnO1 junk@main

これを全体コピーします。

4.ブラウザの[Compute Engine]から[VM インスタンス]を選択、接続先VMの名前リンクをクリックし、詳細画面に移動し下部のSSHキーの[編集]ボタンを押す。

image

5.キーデータ全体を入力と出ているところに先ほどコピーしたキーファイルの中身をペイストする。

image

6.[保存]ボタンを押す

動作確認

接続元から接続先にsshで接続してみる。

junk@main:~/.ssh$ ssh junk@worker1
Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-55-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Jul 17 17:34:13 UTC 2015

  System load:  0.0               Processes:           85
  Usage of /:   0.9% of 98.40GB   Users logged in:     1
  Memory usage: 2%                IP address for eth0: 10.240.213.61
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.

New release '14.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


Your Hardware Enablement Stack (HWE) is supported until April 2017.

Last login: Fri Jul 17 17:15:41 2015 from 10.240.67.98
junk@worker1:~$ 

問題なくパス無しでssh出来ました!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away