2015年1月10日土曜日

LinuxでのGit設定と利用

1. Gitインストール(root)で作業
# yum install git

2. 鍵の生成(対象ユーザで行う)
$ ssh-keygen -C "github"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/j11000/.ssh/id_rsa):
そのままエンター
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
パスワードは任意
Your identification has been saved in id_rsa_github.
Your public key has been saved in id_rsa_github.pub.
これでホームディレクトリの.sshフォルダに id_rsa_github.pub, id_rsa_githubが生成されます。

3. GithubのサイトにSSHの公開鍵を登録
Githubのアカウントを作成し、ログインしてください。
https://github.com/
右上 Setting -> SSH keys -> Add SSH Key
Title : ホスト名など(例 j11000.sangi01.net)
Keyは
$ cat ~/.ssh/id_rsa.pub
を発行し、出力された結果を貼付けてください。
Add keyを押して登録します。

4. 秘密鍵をローカルに登録
$ eval `ssh-agent`
$ ssh-add ~/.ssh/id_rsa

5. アップロードのための設定
[Github側]
Githubに今回のリポジトリを作成します。図のようにNEWをクリックします。
Repository Nameだけ入力してCreate Repositoryをクリックします。
[ホスト側]
初期設定
$ git config --global user.name githubユーザ名
$ git config --global user.email githubに登録したメールアドレス
ホームディレクトリにあるwwwの中身をアップロードしてみます。
$ ls
www
$ cd www
$ git init
$ touch README
$ git commit -m 'first commit'
$ git remote add origin git@github.com:smzn/j11000.git
$ git add *
$ git commit
Are you sure you want to continue connecting (yes/no)? yes とします。
commitが完了しました。

Github側のリポジトリを見てみます
ファイルがアップロードされています。

参考サイト
http://nullpopopo.blogcube.info/2012/04/github_centos6.html
http://qiita.com/gitya107/items/0fc0c87ceaf7299e7fb3
http://tweeeety.hateblo.jp/entry/2014/08/08/213935


==2019/04/01追記==
・ssh接続の確認には $ ssh -T git@github.com
・$ git commitではコミットできない
 →$ git push origin master でコミットできる

参考
https://qiita.com/tesoro/items/af4a80b7ebb9ad34e5fd
https://qiita.com/irxground/items/80dc6432e7d9d2b8b2a9
https://nishinatoshiharu.com/how-to-gitpush-with-ssh/http://blog.uso400.net/xibhuairunorokaraizu/