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?

More than 5 years have passed since last update.

SSH Keysを作ってGitHubへ登録

Last updated at Posted at 2019-09-06

よく忘れて、その度に調べる羽目になるので、記事にします。

ssh-keygen

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

保存する場所を聞かれます。

Enter file in which to save the key (/Users/user_name/.ssh/id_rsa):

適当にディレクトリ作ってサービスごと(githubとかbitbucketとか)に保存するのがベターな気がします。

$ mkdir -p ~/.ssh/github`をした後に、~/.ssh/github/id_rsaと入力しましょう。

パスワードを聞かれます。設定しておきましょう。

Enter passphrase (empty for no passphrase):

githubやbitbucketに登録

pbcopy < ~/.ssh/github/id_rsa.pub

公開鍵を登録しましょう。

vim config

以下のような感じでconfigファイルを書いておきましょう。役立ちます。

$ vi ~/.ssh/config
Host github.com
    User git
    Port 22
    HostName github.com
    identityFile ~/.ssh/github/id_rsa
    TCPKeepAlive yes
    IdentitiesOnly yes
    ForwardAgent yes

どう役立つかというと、こんな風に書きたくないから設定しておこうって感じです。

$ ssh ユーザー名@ホスト名 -i ~/.ssh/鍵の名前 -p ポート番号

もう少し詳しく知りたい方はこちらの記事を読むといいです。
https://qiita.com/passol78/items/2ad123e39efeb1a5286b

ssh-add

いちいちパスワードを入力したくないので、ssh-agentに作った秘密鍵を登録しておきましょう。

$ ssh-add -K ~/.ssh/github/id_rsa

登録できたか確認。

$ ssh-add -l

最後に接続できるか試しましょう。

$ ssh github.com
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?