GogsによるプライベートGitサーバーの構築とSSHに関する2つの問題点

Gogs公式サイト:https://gogs.io/docs/installation/install_from_binary

インストール方法は、通常のマシン環境とDockerの2種類があります。通常のマシンでのインストールを推奨します。Linuxのgitユーザーで実施してください(Docker版の場合は無視)。

初期設定を再実行したい場合、/home/git/gogs/custom/conf/app.ini ファイルを削除し、./gogs web を再起動するだけでOKです。リポジトリやユーザー情報は保持されます。

以降は通常マシンでのインストール中にSSH経由でクローンを行う際のトラブル対処について。

SSH鍵認証の設定後もパスワード認証が求められる場合があります。これはgitユーザーのホームディレクトリ.sshディレクトリ、そしてauthorized_keysファイルのパーミッションが適切でないことが原因である可能性があります。詳しくは「SSH鍵認証が有効にならない問題の解決法」を参照してください。

その後、ssh –T user@host では正常に接続できるのに、git clone が失敗する現象が発生することがあります。エラーメッセージは以下のようになります。

$ git clone xxxxxxxxxxxxxxxxxxxx
Cloning into 'xxxxx'
Gogs: Internal error
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

SSHや権限の問題と考えがちですが、ログファイル /home/git/gogs/log/hooks/serv.log を確認してみてください。エラー内容が以下のような形式で記録されている場合:

2021/09/08 18:50:01 [ERROR] [...ogs.io/gogs/internal/cmd/serv.go:47 fail()] Failed to execute git command: exec: "git-upload-pack": executable file not found in $PATH
2021/09/08 19:03:46 [ERROR] [...ogs.io/gogs/internal/cmd/serv.go:47 fail()] Failed to execute git command: exec: "git-upload-pack": executable file not found in $PATH
2021/09/08 19:03:50 [ERROR] [...ogs.io/gogs/internal/cmd/serv.go:47 fail()] Failed to execute git command: exec: "git-upload-pack": executable file not found in $PATH
2021/09/08 19:08:50 [ERROR] [...ogs.io/gogs/internal/cmd/serv.go:47 fail()] Failed to execute git command: exec: "git-upload-pack": executable file not found in $PATH
2021/09/08 19:18:10 [ERROR] [...ogs.io/gogs/internal/cmd/serv.go:47 fail()] Failed to execute git command: exec: "git-upload-pack": executable file not found in $PATH

この記事を参考にしてください:

gogsリポジトリ管理ソフト exec: "git-upload-pack": executable file not found in $PATH

上記2つの問題点を解消すれば、通常の運用が可能になります。さらに自動起動機能を設定したい場合は、以下のリンクを参考にしてください:

https://www.jianshu.com/p/c9ca7c16bd1f、https://www.codenong.com/cs109129829/

後者はapp.iniの各設定値の詳細を解説しており、興味があれば確認すると良いでしょう。

基本的にはコピーして適用するだけで動作しますが、起動時にログに「not found in $PATH」というエラーが続く場合は、git関連コマンドを /sbin ディレクトリにシンボリックリンクを貼ってみてください。

タグ: Gogs Git SSH linux セキュリティ

7月6日 20:28 投稿