3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LightsailでGithubを使う

Last updated at Posted at 2022-02-28

Lightsailのインスタンス内をGithubで管理したい時などに

LightsailインスタンスにGitをインストール

$ sudo apt-get install git-all

LightsailインスタンスにSSH接続のため,秘密鍵作成

$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/bitnami/.ssh/id_rsa):    
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/bitnami/.ssh/id_rsa.
Your public key has been saved in /home/bitnami/.ssh/id_rsa.pub.

/home/bitnami/.ssh/id_rsa にid_rsaが作成されます

cat ~/.ssh/id_rsa.pub 

で秘密鍵の内容が表示されるので,コピー

GitHubアカウントに秘密鍵を登録

アカウント→setting→SSH and GPG keys→New SSH Key
でコピーした内容をペーストし登録

$ ssh -T git@github.com

で接続できるか確認

接続成功すると,

Hi ○○○○! You've successfully authenticated, but GitHub does not provide shell access.

みたいなメッセージが出てくれば接続できています

あとは
git remote add origin git@github.com:{ユーザー名}/{リポジトリ名}.git
でリポジトリを追加してpushしてあげるやら
git clone git@github.com:{ユーザー名}/{リポジトリ名}.git
でcloneしてあげる

※ここでは上記の通りSSL形式で通信すること。
 HTTPSだとユーザー名とパスワードを都度求められてしまいます。

ターミナル上からSSH接続

ターミナルからgithubの変更箇所をpullしてくる時は,

ssh -i ~/.ssh/○○○.pem bitnami@{インスタンスのIP} 
git pull origin {ブランチ名}
git push -u origin {ブランチ名}
3
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?