Gitサーバ構築 » 履歴 » バージョン 1
Tatsuya ISHIGAKI, 2025/10/24 01:10
| 1 | 1 | Tatsuya ISHIGAKI | # Gitサーバ構築 |
|---|---|---|---|
| 2 | |||
| 3 | ## 参考web |
||
| 4 | - [Qiita] [Gitで使用するSSHキーを指定する方法あれこれ](https://qiita.com/ryounagaoka/items/b661f96f599e26a04589) |
||
| 5 | - git サーバへの SSH プロトコル接続をする際に、鍵を指定する方法 |
||
| 6 | - [Qiita] [~/.ssh/configについて](https://qiita.com/passol78/items/2ad123e39efeb1a5286b) |
||
| 7 | - ssh の config ファイルについての説明 |
||
| 8 | - [Qiita] [git config --global --add safe.directory '...' が出たとき](https://qiita.com/yosse95ai/items/2ca93e2ea585b321f777) |
||
| 9 | - [侍テラコヤ] [phpをgitとgithubにつなぐ際のgit config --global --add safe.directory C:/xampp/htdocsについて](https://terakoya.sejuku.net/question/detail/38140) |
||
| 10 | - git 2.25.2 以降では既定動作として不明ディレクトリでの操作制限がある、と説明 |
||
| 11 | |||
| 12 | ## 実施記録 |
||
| 13 | |||
| 14 | ### redmine.smismith.com |
||
| 15 | ```bash |
||
| 16 | $ cd /opt |
||
| 17 | $ sudo mkdir ./git |
||
| 18 | $ sudo chown smith.smith ./git |
||
| 19 | $ cd ./git |
||
| 20 | $ git init --bare ./onservertest.git |
||
| 21 | Initialized empty Git repository in /opt/git/onservertest.git/ |
||
| 22 | $ ls -la /opt/git |
||
| 23 | total 12 |
||
| 24 | drwxr-xr-x. 3 smith smith 4096 Oct 23 21:16 . |
||
| 25 | drwxr-xr-x. 6 root root 4096 Oct 23 19:44 .. |
||
| 26 | drwxr-xr-x. 7 smith smith 4096 Oct 23 21:16 onservertest.git |
||
| 27 | ``` |
||
| 28 | |||
| 29 | ### cucumber |
||
| 30 | ```bash |
||
| 31 | $ git clone smith@redmine.smismith.com:/opt/onservertest.git |
||
| 32 | Cloning into 'onservertest'... |
||
| 33 | The authenticity of host 'redmine.smismith.com (133.18.105.188)' can't be established. |
||
| 34 | ED25519 key fingerprint is SHA256:UnoojAwYi8UAQxBrx14QYKvdRWlb4lErpVpaNkjm3Fs. |
||
| 35 | This key is not known by any other names. |
||
| 36 | Are you sure you want to continue connecting (yes/no/[fingerprint])? yes |
||
| 37 | Warning: Permanently added 'redmine.smismith.com' (ED25519) to the list of known hosts. |
||
| 38 | smith@redmine.smismith.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic). |
||
| 39 | fatal: Could not read from remote repository. |
||
| 40 | |||
| 41 | Please make sure you have the correct access rights |
||
| 42 | and the repository exists. |
||
| 43 | ``` |
||
| 44 | - fingerprint の確認後、認証失敗した |
||
| 45 | - 鍵指定してないから ? |
||
| 46 | - 鍵指定の方法は ? |
||
| 47 | - 鍵指定方法を調査して再実施 ([調査結果](#ssh-鍵指定)) |
||
| 48 | - `~/.ssh/config` にホスト指定で鍵を記載 |
||
| 49 | - 先程の clone はそもそもパスが間違ってもいた |
||
| 50 | - NG `/opt/onservertest.git` |
||
| 51 | - OK `/opt/git/onservertest.git` |
||
| 52 | |||
| 53 | ```bash |
||
| 54 | $ git clone smith@redmine.smismith.com:/opt/git/onservertest.git |
||
| 55 | Cloning into 'onservertest'... |
||
| 56 | Enter passphrase for key '/c/Users/green/.ssh/id_rsa_Kagoya_Redmine_smith': |
||
| 57 | warning: You appear to have cloned an empty repository. |
||
| 58 | ``` |
||
| 59 | - パスフレーズを入力の後、clone が完了した |
||
| 60 | - 2ファイルを commit して、push も成功した |
||
| 61 | |||
| 62 | ### GINGER |
||
| 63 | ```bash |
||
| 64 | $ git clone smith@redmine.smismith.com:/opt/git/onservertest.git |
||
| 65 | Cloning into 'onservertest'... |
||
| 66 | Enter passphrase for key '/c/Users/tatsuya/.ssh/id_rsa': |
||
| 67 | remote: Enumerating objects: 7, done. |
||
| 68 | remote: Counting objects: 100% (7/7), done. |
||
| 69 | remote: Compressing objects: 100% (7/7), done. |
||
| 70 | remote: Total 7 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0) |
||
| 71 | Receiving objects: 100% (7/7), done. |
||
| 72 | Resolving deltas: 100% (2/2), done. |
||
| 73 | ``` |
||
| 74 | - 鍵はデフォルトのものが自動で使用された |
||
| 75 | - パスフレーズを入力したら clone 成功 |
||
| 76 | |||
| 77 | ```bash |
||
| 78 | $ cd ./onservertest/ |
||
| 79 | $ ll |
||
| 80 | total 64 |
||
| 81 | -rw-r--r-- 1 tatsuya 197121 3240 10月 24 09:05 wiki_GitServer.md |
||
| 82 | -rw-r--r-- 1 tatsuya 197121 3423 10月 24 09:05 wiki_GitServerConstruction.md |
||
| 83 | |||
| 84 | $ git status |
||
| 85 | fatal: detected dubious ownership in repository at 'D:/GitSurvey/onservertest' |
||
| 86 | 'D:/GitSurvey/onservertest' is on a file system that does not record ownership |
||
| 87 | To add an exception for this directory, call: |
||
| 88 | |||
| 89 | git config --global --add safe.directory D:/GitSurvey/onservertest |
||
| 90 | ``` |
||
| 91 | - git リポジトリとして使用するには `safe.directory` にディレクトリを登録する必要がある様子 |
||
| 92 | - このディレクトリは SD カードだから ? |
||
| 93 | - `safe.difrectory` 設定も調べるか |
||
| 94 | |||
| 95 | ``` |
||
| 96 | $ git config --global --add safe.directory D:/GitSurvey/onservertest |
||
| 97 | ``` |
||
| 98 | - `safe.directory` へ登録したら使用可能になった |
||
| 99 | |||
| 100 | ## SSH 鍵指定 |
||
| 101 | |||
| 102 | ### ~/.ssh/config で指定 |
||
| 103 | - ファイル `~/.ssh/config` (Windows11 では `C:\ユーザー\(ユーザ名)\.ssh\config` 等) を以下の様に記載 |
||
| 104 | ``` |
||
| 105 | Host redmine.smismith.com |
||
| 106 | HostName redmine.smismith.com |
||
| 107 | IdentityFile ~/.ssh/id_rsa_Kagoya_Redmine_smith |
||
| 108 | ``` |
||
| 109 | |||
| 110 | |項目|説明| |
||
| 111 | |:-:|---| |
||
| 112 | |Host|任意の接続名(hoge)| |
||
| 113 | |HostName|ホスト名| |
||
| 114 | |User|ユーザー名| |
||
| 115 | |Port|ポート番号| |
||
| 116 | |IdentityFile|鍵へのPATH(例えば~/.ssh/hoge.key)| |
||
| 117 | |||
| 118 | ### core.sshCommand を git コマンドに指定 |
||
| 119 | - git コマンドの `-c` オプションで `"core.sshCommand=ssh -i ~/.ssh/id_rsa_example -F /dev/null"` を指定する |
||
| 120 | - `~/.git/config` にも記録され、その後も使用される |
||
| 121 | - clone でのコマンド全体 |
||
| 122 | ```bash |
||
| 123 | git clone -c "core.sshCommand=ssh -i <鍵パス> -F /dev/null" <接続先情報> |
||
| 124 | ``` |
||
| 125 | - 後から鍵指定する場合は config に設定 |
||
| 126 | ```bash |
||
| 127 | git config core.sshCommand "ssh -i <鍵パス> -F /dev/null" |
||
| 128 | ``` |
||
| 129 | |||
| 130 | ### 環境変数 GIT_SSH_COMMAND で指定 |
||
| 131 | - **core.sshCommand** と同じ内容を環境変数で指定 |
||
| 132 | - git の config には記録されない |
||
| 133 | |||
| 134 | ## safe.directory 設定 |