LoginSignup
6
8

More than 3 years have passed since last update.

GCEに端末からsshでアクセス,ファイルの転送

Last updated at Posted at 2017-12-25

Google Compute Engineインスタンスへのssh接続 メモ

目的

Google Compute Engineで作ったInstanceに,いつも使っているTerminalから,いつものようにsshでAccessしたい。

0. ssh鍵の作成

以前の記事を参考に,

sshの設定(passwordなしでsshログイン(scp)する)

1. ssh鍵のformat

ssh-rsa [KEY_VALUE] [USERNAME]

作成したssh鍵のパブリックキーファイルのフォーマットを編集する。
[KEY_VALUE]の後ろの通常はコメントとなる領域を,エディタを使ってユーザー名に書き換える。

例えば,

vi ~/.ssh/id_rsa.pub

で,ユーザー名(hogehoge@gmail.com)を鍵の末尾に。

ssh-rsa dsafhdlkaijklafkdlfh...dfjsaifjiof hogehoge@gmail.com

これを,ブラウザから設定する。

Google Cloud Platform -> Compute Engine -> Metadata -> SSH keys

Edit -> コピペ -> Save

これで準備完了。

2. ssh接続

IP address を調べる(VMインスタンス一覧のExternal IPを見ればよい)。

端末から

ssh -l hogehoge 104.199.144.176

もしくは,

ssh -l hogehoge 104.199.144.176 -i ~/.ssh/id_rsa

接続できない場合、インスタンスのリブート(再起動)が必要かもしれない。
(ネットワーク設定の再構成)

3. ファイル転送

scpを使う。

例えば

scp something.txt hogehoge@104.199.144.176:

参考

公式ドキュメント

  • Linuxインスタンスへの接続

  • SSH 認証鍵ペアの設定方法

6
8
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
6
8