git勉強下準備ドリル
gitの使い方を教える機会があったので、 その勉強をする前にするべきことリスト
github(or gitlab etc..)のアカウントを作ってみる。
臨機応変に…
rsa鍵を登録してsshconfigを書く
rsa鍵作成
はじめのうちは~/.ssh/keysみたいなディレクトリにいれて管理するのがよいと思う
$ mkdir -p ~/.ssh/keys $ cd ~/.ssh/keys $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/cocu/.ssh/id_rsa): github ← Enter passphrase (empty for no passphrase): ←わからないうちは何も入れなくて良い Enter same passphrase again: ←わからないうちは何も入れなくて良い Your identification has been saved in hoge. Your public key has been saved in hoge.pub. The key fingerprint is: 33:56:3a:45:f0:dc:db:86:56:e8:6e:e3:e1:34:9e:b6 cocu@cocu-MBA-Arch The key's randomart image is: +--[ RSA 2048]----+ | ... | | + . . | | = o . | | + . = | | S = o | | . + o . | | B | | *.= | | .E. | +-----------------+ $ ls -al #きちんと作成されたか確認 -rw------- 1 cocu cocu 1679 Aug 16 18:03 github ←秘密鍵 -rw-r--r-- 1 cocu cocu 400 Aug 16 18:03 github.pub ←公開鍵
登録
githubならば
https://github.com/settings/profile SSH keys→add ssh keys
github.pubをコピペする。
これでgithub.comにsshでアクセスできるようになった。
$ ssh github.com -i ~/.ssh/keys/github -l git PTY allocation request failed on channel 0 Hi cocu! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
sshconfig
この状態では毎回秘密鍵の場所を指定しないといけなくめんどいので、 sshconfigを書いて簡略化させる。
~/.ssh/config
に追記、なかったら作成
Host github.com User git HostName github.com IdentityFile ~/.ssh/keys/github
ssh github.com
下みたいなメッセージが現れてcocuが自分の設定した名前ならおk
$ ssh github.com PTY allocation request failed on channel 0 Hi cocu! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
git config
多くの人がgithub idと同じだったりする。
$ git config --global user.name ユーザー名 $ git config --global user.email メールアドレス
commitした時のメッセージに関係している。