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?

GitHubのSSH設定

Last updated at Posted at 2024-01-13

ローカル環境でGitHubとやりとりする場合、GitHubに公開鍵を登録する必要がある。
以下手順。

# GitHubに公開鍵を登録しないとへアクセスできない
.ssh % ssh -T git@github.com
git@github.com: Permission denied (publickey).

# ディレクトリを移動
.ssh % cd ~/.ssh

# 公開鍵、秘密鍵がないことを確認

.ssh % ls -la
total 16
drwx------   4 kinu  staff  128  1 13 21:24 .
drwxr-x---+ 22 kinu  staff  704  1 13 21:19 ..
-rw-------   1 kinu  staff  828  1 13 21:09 known_hosts
-rw-r--r--   1 kinu  staff   92  1 13 11:46 known_hosts.old

# 公開鍵、秘密鍵を生成
.ssh % ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/kinu/.ssh/id_rsa): 
# パスフレーズは設定しないので全てエンター
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/kinu/.ssh/id_rsa
Your public key has been saved in /Users/kinu/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx kinu@KiunMacBookPro-Pro.local
The key's randomart image is:
+---[RSA 3072]----+
|  .     . o.. .+O|
| =   . . = o .+.B|
|+ + = o   @    B+|
|.. o B = B =  .o+|
|    . = S E . ..o|
|     . . o   o  .|
|            .    |
|                 |
|                 |
+----[SHA256]-----+

# 公開鍵の中身をコピー(pbcopyコマンドはMac用)
.ssh % pbcopy < ~/.ssh/id_rsa.pub 

## GitHubへアクセスできることを確認
.ssh % ssh -T git@github.com
Hi kinucode! You've successfully authenticated, but GitHub does not provide shell access.

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?