0
0

More than 1 year has passed since last update.

GitHub に ssh で接続

Last updated at Posted at 2023-07-29

Key の作成

go_key_gen
ssh-keygen -t rsa -N "" -f key_example

実行結果
$HOME/.ssh で実行します。

$ ./go_key_gen 
Generating public/private rsa key pair.
Your identification has been saved in key_example
Your public key has been saved in key_example.pub
The key fingerprint is:
SHA256:9DXUmxTGjcGxZ8XdmwFhEiE0yK6He8BVqpp/w0VxCHU uchida@example
The key's randomart image is:
+---[RSA 3072]----+
|      . += E+BB*=|
|       + .+.o.*+=|
|      . = . o..o*|
|       = = o .o= |
|    . * S +      |
|     O . .       |
|    . * .        |
|     . =         |
|      ..o        |
+----[SHA256]-----+

次のファイルが作成されます。

key_example
key_example.pub

key_example.pub を GitHub にコピーペーストで登録します。

github.com で、キーの登録

settings -> SSH and GPG keys
image.png

New SSH Key をクリック
image.png

Add SSH Key をクリックして登録

.ssh/config の作成

.ssh/config
Host github.com
  User git
  Hostname github.com
  IdentityFile ~/.ssh/key_example

ssh 接続できるかの確認

ssh -T git@github.com

接続できる場合

$ ssh -T git@github.com
Hi ekzemplaro! You've successfully authenticated, but GitHub does not provide shell access.

接続できない場合

$ ssh -T git@github.com
git@github.com: Permission denied (publickey).

クローン

git clone git@github.com:example/sample01.git

既存のリポジトリーに pull

リポジトリーが、https で pull されたか、 ssh で pull されたかを調べる

git remote -v

ssh で pull された場合

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

https で pull された場合

$ git remote -v
origin	https://github.com/example/sample01.git (fetch)
origin	https://github.com/example/sample01.git (push)

https から ssh に切り替える

git remote set-url origin git@github.com:example/sample01.git

pull

git pull
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