見出し画像

EC2からリポジトリをチェックアウト

という超基本の章

参考URL

*同じカテゴリ記事のマガジンは、こちらにあります

ーー

前提条件

EC2にSSH

手順

Bitbucketに登録する鍵ファイルを作成する

$ cd ~/.ssh
$ mkdir bitbucket
$ ssh-keygen -t rsa -C <コメント>
$ Enter file in which to save the key (/home/ec2-user/.ssh/id_rsa): /home/ec2-user/.ssh/bitbucket/id_rsa
$ Enter passphrase (empty for no passphrase): #何も入力せずEnterキーを押す
$ Enter same passphrase again: #何も入力せずEnterキーを押す

id_rsaが秘密鍵、id_rsa.pubが公開鍵

秘密鍵のパーミッションを変更

自分以外のユーザーが読めないように

$ chmod 600 ~/.ssh/bitbucket/id_rsa


公開鍵をBitbucketへ登録


公開鍵の内容をコピーし「鍵を追加」

cat ~/.ssh/bitbucket/id_rsa.pub


SSHしてみる

$ touch ~/.ssh/config
$ chmod 700 config
Host bitbucket.org
  HostName bitbucket.org
  IdentityFile ~/.ssh/bitbucket/id_rsa
  User git
  Port 22
  TCPKeepAlive yes
  IdentitiesOnly yes
ssh bitbucket.org

The authenticity of host 'bitbucket.org (IPアドレス)' can't be established.
ED25519 key fingerprint is SHA256:****.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'bitbucket.org' (ED25519) to the list of known hosts.
PTY allocation request failed on channel 0
authenticated via ssh key.

You can use git to connect to Bitbucket. Shell access is disabled
Connection to bitbucket.org closed.

「gitで接続できるけどShellアクセスは許可されていない」と出力されるが、これでOK

Gitのインストール

sudo yum install git

クローン先ディレクトリ作成

$ mkdir -p ~/work

クローン(BitbucketリポにCloneボタンで表示もできます)

git clone git@bitbucket.org:アカウント名/リポジトリ名.git

ブランチ確認

ブランチ確認
$ git branch -a

ブランチ・チェックアウト

*ブランチ名はremotesから開始されているが、remotes/は省いて指定
$ git chckout -b <ここでのブランチ名> -t ブランチ名


この記事が気に入ったらサポートをしてみませんか?