LoginSignup
22
11

More than 5 years have passed since last update.

AWS Cloud9 でgithubの設定をする

Last updated at Posted at 2018-11-21

環境

  • AWS Cloud9 (シンガポールリージョンのEC2上で動作)
  • Amazon Linux2
  • bash

できるようになりたいこと

SSH認証でgithub上のリモートリポジトリにpushできるようにする

手順

普通のLinux環境における設定とおなじ

公開鍵の設定

キーペアを作成する

いくつかの記事だと、デフォルトでキーペアがすでに存在していると書かれているものもあったが、現在はない様子
なので、githubに登録する用の秘密鍵/公開鍵のペアを作成する

#cloud9上のbash
$ cd ~/.ssh
$ ssh-keygen
#ここでキーを出力するディレクトリやパスワードを聞かれるのでよしなに入力する

作成した公開鍵をコピーしてgithubに登録する

  1. 「Settings」→「SSH and GPG keys」→「New SSH key」ボタンをクリック
  2. titleにわかりやすい名前(例:cloud9など)、Keyにコピーした公開鍵をペーストする
  3. 「Add SSH Key」をクリック
  4. 公開鍵の登録完了

リポジトリの設定

リポジトリをclone

リポジトリをcloneするときは、「Use SSH」からgit@github.com:username/repository_name.gitをコピーしてcloneする

$ git clone git@github.com:username/repository_name.git
#このとき、先ほどssh-keygenで生成した際に入力したパスワードを聞かれるので入力する
#パスワードが一致すればgit cloneがはじまる

設定されているリモートリポジトリの確認

リモートリポジトリの確認
先ほどcloneしたリポジトリが設定されているはず

$ git remote -v
origin  git@github.com:username/repository_name.git (fetch)
origin  git@github.com:username/repository_name.git (push)

コミットしてみる

なにもcommitするものがなければ、--allow-emptyオプションをつけてcommitする

$ git commit --allow-empty
$ git push origin master

これで、githubのユーザ名やパスワードを聞かれずにリモートリポジトリにpushできればOK!

22
11
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
22
11