0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Amazon Linux 2023上でGitをインストールし、GitHubとSSH接続するまでの手順

Posted at

環境

  • EC2
    • OS: Amazon Linux 2023
  • EC2インスタンスは起動済みであること

手順1:Gitのインストール

パッケージのアップデート

$ sudo dnf -y update
Last metadata expiration check: 9:57:17 ago on Sun May  4 00:30:59 2025.
Dependencies resolved.
Nothing to do.
Complete!

Gitのインストール

sudo dnf install -y git

Gitのバージョン確認をすることで、Gitがインストールされたかを確認します

$ git version
git version 2.47.1

手順2:公開鍵と秘密鍵の作成

.sshディレクトリに移動

cd .ssh

公開鍵と秘密鍵の作成

ssh-keygen -t ed25519
# 空Enterでも大丈夫
Enter file in which to save the key (/home/ec2-user/.ssh/id_ed25519):
# パスワードはできれば入力した方がいいです
Enter passphrase (empty for no passphrase):
# 1回目と同じパスワードを入力
Enter same passphrase again:

公開鍵、秘密鍵が作成されたかを確認します。

$ ls -la
-rw-------. 1 ec2-user ec2-user  94 May  3 06:16 authorized_keys
-rw-------. 1 ec2-user ec2-user 464 May  6 07:11 id_ed25519
-rw-r--r--. 1 ec2-user ec2-user 136 May  6 07:11 id_ed25519.pub

セキュリティ確保のために公開鍵と秘密鍵の権限を読み取り専用に変更

chmod 400 id_ed25519 id_25519.pub

読み取り専用に変更されたかどうかを確認します

$ ls -la
-rw-------. 1 ec2-user ec2-user  94 May  3 06:16 authorized_keys
-r--------. 1 ec2-user ec2-user 464 May  6 07:11 id_ed25519
-r--------. 1 ec2-user ec2-user 136 May  6 07:11 id_ed25519.pub

手順3:SSHキーをGitHubに登録

  1. GitHubにログイン
  2. 右上のアイコンをクリックし、Settings(設定)をクリック
  3. 左のサイドバーにある「SSH and GPG keys」をクリック
  4. 右上の「New SSH key」をクリック
設定項目 入力内容
Title sample用
Key type Authentication Key
Key 公開鍵であるid_25519.pubの中身を貼り付け

入力が完了しましたら、Add SSH keyをクリックします

Gitに接続できるかを確認します。

$ ssh -T git@github.com
Hi <GitHubのユーザー名>! You've successfully authenticated, but GitHub does not provide shell access.

まとめ

Gitのインストール後、公開鍵と秘密鍵を作成してGitHubに公開鍵を登録します。接続確認が成功すれば、リモートリポジトリに問題なくアクセスできるようになります。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?