プロジェクト

全般

プロフィール

操作

Gitサーバ構築

参考web

実施記録

redmine.smismith.com

$ cd /opt
$ sudo mkdir ./git
$ sudo chown smith.smith ./git
$ cd ./git
$ git init --bare ./onservertest.git
Initialized empty Git repository in /opt/git/onservertest.git/
$ ls -la /opt/git
total 12
drwxr-xr-x. 3 smith smith 4096 Oct 23 21:16 .
drwxr-xr-x. 6 root  root  4096 Oct 23 19:44 ..
drwxr-xr-x. 7 smith smith 4096 Oct 23 21:16 onservertest.git

cucumber

$ git clone smith@redmine.smismith.com:/opt/onservertest.git
Cloning into 'onservertest'...
The authenticity of host 'redmine.smismith.com (133.18.105.188)' can't be established.
ED25519 key fingerprint is SHA256:UnoojAwYi8UAQxBrx14QYKvdRWlb4lErpVpaNkjm3Fs.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'redmine.smismith.com' (ED25519) to the list of known hosts.
smith@redmine.smismith.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
  • fingerprint の確認後、認証失敗した
    • 鍵指定してないから ?
    • 鍵指定の方法は ?
  • 鍵指定方法を調査して再実施 (調査結果)
    • ~/.ssh/config にホスト指定で鍵を記載
  • 先程の clone はそもそもパスが間違ってもいた
    • NG /opt/onservertest.git
    • OK /opt/git/onservertest.git
$ git clone smith@redmine.smismith.com:/opt/git/onservertest.git
Cloning into 'onservertest'...
Enter passphrase for key '/c/Users/green/.ssh/id_rsa_Kagoya_Redmine_smith':
warning: You appear to have cloned an empty repository.
  • パスフレーズを入力の後、clone が完了した
  • 2ファイルを commit して、push も成功した

GINGER

$ git clone smith@redmine.smismith.com:/opt/git/onservertest.git
Cloning into 'onservertest'...
Enter passphrase for key '/c/Users/tatsuya/.ssh/id_rsa':
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 7 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (7/7), done.
Resolving deltas: 100% (2/2), done.
  • 鍵はデフォルトのものが自動で使用された
  • パスフレーズを入力したら clone 成功
$ cd ./onservertest/
$ ll
total 64
-rw-r--r-- 1 tatsuya 197121 3240 10月 24 09:05 wiki_GitServer.md
-rw-r--r-- 1 tatsuya 197121 3423 10月 24 09:05 wiki_GitServerConstruction.md

$ git status
fatal: detected dubious ownership in repository at 'D:/GitSurvey/onservertest'
'D:/GitSurvey/onservertest' is on a file system that does not record ownership
To add an exception for this directory, call:

        git config --global --add safe.directory D:/GitSurvey/onservertest
  • git リポジトリとして使用するには safe.directory にディレクトリを登録する必要がある様子
    • このディレクトリは SD カードだから ?
    • safe.difrectory 設定も調べるか
$ git config --global --add safe.directory D:/GitSurvey/onservertest
  • safe.directory へ登録したら使用可能になった

SSH 鍵指定

~/.ssh/config で指定

  • ファイル ~/.ssh/config (Windows11 では C:\ユーザー\(ユーザ名)\.ssh\config 等) を以下の様に記載

    Host redmine.smismith.com
      HostName redmine.smismith.com
      IdentityFile ~/.ssh/id_rsa_Kagoya_Redmine_smith
    
    項目 説明
    Host 任意の接続名(hoge)
    HostName ホスト名
    User ユーザー名
    Port ポート番号
    IdentityFile 鍵へのPATH(例えば~/.ssh/hoge.key)

core.sshCommand を git コマンドに指定

  • git コマンドの -c オプションで "core.sshCommand=ssh -i ~/.ssh/id_rsa_example -F /dev/null" を指定する
  • ~/.git/config にも記録され、その後も使用される
  • clone でのコマンド全体
    git clone -c "core.sshCommand=ssh -i <鍵パス> -F /dev/null" <接続先情報>
    
  • 後から鍵指定する場合は config に設定
    git config core.sshCommand "ssh -i <鍵パス> -F /dev/null"
    

環境変数 GIT_SSH_COMMAND で指定

  • core.sshCommand と同じ内容を環境変数で指定
  • git の config には記録されない

safe.directory 設定

Tatsuya ISHIGAKI さんが約2ヶ月前に更新 · 1件の履歴