いまさらながらLinux上(LMDE)からGitHubを使ってみよう
フツーにgit cloneとかしてたからフツーに使えると思ってたけど、鍵の設定とかしなきゃいけなかったみたい。
公式チュートリアル
Set Up Git
参考
githubに適当にリポジトリ作って開発環境としてみるメモ①-さくらvpsやら会社のlinuxにgit cloneってみる
Ubuntuでgithubを使う
前提はGitHubのアカウントがすでにあること。
1.いきなりやって失敗したこと
ユーザー名とアカウントのメールアドレス打ってみたらすぐ接続できるかと思った
$ git config --global user.name "t-min"
$ git config --global user.email "na8ctm@gmail.com"
$ git clone git@github.com:t-min/bootstrapforfc22clumn.git
Cloning into 'bootstrapforfc22clumn'...
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Permission denied でござる。
2.鍵作って登録
Windows版でつないだ時に作った鍵見れるかと思ったけど見れない。ので鍵作って登録しました。
$ ssh-keygen -C "for_github"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tmin/.ssh/id_rsa): id_rsa_git
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_git.
Your public key has been saved in id_rsa_git.pub.
The key fingerprint is:
b6:e8:48:9a:d3:d9:87:90:d4:fc:d0:11:1e:01:13:52 for_github
The key's randomart image is:
id_rsa_git
id_rsa_git.pub
の2つができてるので、これを.ssh以下に移動。
$ cp id_rsa_git id_rsa_git.pub .ssh
3.GitHubに鍵追加
ログインした状態で右上の方の歯車アイコンSettingからSSH Keys。
右上のAdd SSH Keyから追加。
Keyの名前は適当に。(今回はGithub for linux)で、Keyのところにさっき作ったkey_pubの方をコピペ。
$ cat .ssh/id_rsa_git.pub
これの内容まんまコピーです。
ここでもっかい
$ ssh -t github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
また拒否られました。
Generating SSH keys
どーもsshの設定が必要?
$ eval "$(ssh-agent -s)"
Agent pid 20878
$ ssh-add ~/.ssh/id_rsa_git
Enter passphrase for /home/tmin/.ssh/id_rsa_git:
これでパスワードを入力すると・・・
$ ssh -T git@github.com
Hi t-min! You've successfully authenticated, but GitHub does not provide shell access.
接続成功です!!
4.cloneとかpushとか
この前作ったFC2テンプレ用のリポジトリ引っ張ってきてみます。
$ git clone git@github.com:t-min/bootstrapforfc22clumn.git
Cloning into 'bootstrapforfc22clumn'...
remote: Counting objects: 22, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 22 (delta 7), reused 22 (delta 7)
Receiving objects: 100% (22/22), 9.21 KiB | 0 bytes/s, done.
Resolving deltas: 100% (7/7), done.
Checking connectivity... done.
$ ls bootstrapforfc22clumn/
bootstrapforfc22clumn
どうやら無事cloneできてますね。
適当なファイル作ってpushできるか試してみます。
$ cd bootstrapforfc22clumn/bootstrapforfc22clumn
$ touch test.txt
$ git add .
$ git commit -m "test commit"
[master 54ca503] test commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 bootstrapforfc22clumn/test.txt
$ git push origin master
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 287 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@github.com:t-min/bootstrapforfc22clumn.git
9f3fcca..54ca503 master -> master
これでGitHubの方にちゃんと反映されてればおっけー。今回は無事成功。
5.新しくリポジトリ作る場合
試しに/home以下にgithubっていうディレクトリ作ってtest.gitとして上げてみます。
$ mkdir github
$ cd github
$ touch test.txt
$ git init
$ ls -la
合計 12
drwxr-xr-x 3 tmin tmin 4096 11月 19 15:32 .
drwxr-xr-x 84 tmin tmin 4096 11月 19 15:31 ..
drwxr-xr-x 7 tmin tmin 4096 11月 19 15:32 .git
-rw-r--r-- 1 tmin tmin 0 11月 19 15:31 test.txt
git initすると.gitが作られます。
$ git commit -m "first commit"
[master (root-commit) f0b44cb] first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
$ git remote add origin git@github.com:t-min/test.git
$ git push -u origin master
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
ダメですね。えぇ。GitHub上にリポジトリ作ってませんでした。GitHubにアクセスしてNew repositoryからtestを作成して
$ git remote add origin git@github.com:t-min/test.git
fatal: remote origin already exists.
$ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 202 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:t-min/test.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
これで反映成功。
FC2のテンプレリポジトリはよくわからないまま作ってしまったのでbootstrapforfc22clumn/bootstrapforfc22clumnというひどいディレクトリ構成になっているので何とかしたい。
新しいリポジトリ作るのを端末上からできたらもっと楽だろうなぁ。
後でよくよく考えたらWindowsでGitHub用にssh-keygenした結果の鍵を.ssh以下にコピってこれば新しい鍵作ることもなかったんじゃないかなもしかして
関連記事
・いまさら始めるGithHub & GistでFC2にソースコード貼り付け
・WindowsでGitHubのリポジトリ管理(Windows10 TPでgit)
Windowsの目次・Linuxの目次・Linuxの目次2・ ・自作PC関連の目次・Web技術関連の目次
全記事一覧・情報サイト新着RSS一覧
Sponsored Link