質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
GitLab

GitLabは Gitoliteをブラウザから管理できるようにする Rubyアプリケーションで、 GitHubのようなサービスをクローズドな環境に独自で構築できるように 公開されたものです。

Q&A

解決済

2回答

14015閲覧

gitlabのsshに接続できない

退会済みユーザー

退会済みユーザー

総合スコア0

GitLab

GitLabは Gitoliteをブラウザから管理できるようにする Rubyアプリケーションで、 GitHubのようなサービスをクローズドな環境に独自で構築できるように 公開されたものです。

0グッド

0クリップ

投稿2015/10/23 16:04

編集2015/10/24 22:08

###発生している問題
gitlabのsshに接続できません
git cloneを行おうとしてもエラーが発生してしまいます。
###エラーメッセージ

shell

ssh

1HOST:~ USER$ git clone git@HOST:USERNAME/REPO.git 2Cloning into 'REPO'... 3Write failed: Broken pipe 4fatal: Could not read from remote repository. 5 6Please make sure you have the correct access rights 7and the repository exists. 8

/var/log/secure

log

1DATE HOST sshd[20456]: Accepted publickey for git from IP port PORT ssh2: RSA finger 2DATE HOST sshd[20456]: pam_unix(sshd:session): session opened for user git by (uid=0) 3DATE HOST sshd[20456]: fatal: safely_chroot: stat("/home/git/"): No such file or directory [postauth] 4DATE HOST sshd[20456]: pam_unix(sshd:session): session closed for user git

###バージョン等
GitLab 8.1.0
GitLab Shell 2.6.5
GitLab API v3
Ruby 2.1.7p400
Rails 4.1.12
CentOS7

###補足
gitlabは公式ドキュメントに従い、yumを使用してインストールしました。
https://about.gitlab.com/downloads/#centos7
ですから、/home/gitなんて存在しないはずなのですが、よくわかりません。

sshで接続してみましたが、Broken pipeで切断されますが、どうやら認証自体は成功しているようです。

shell

1ssh -vT git@HOST 2 3OpenSSH_6.9p1, LibreSSL 2.1.7 4debug1: Reading configuration data /etc/ssh/ssh_config 5debug1: /etc/ssh/ssh_config line 20: Applying options for * 6debug1: /etc/ssh/ssh_config line 102: Applying options for * 7debug1: Connecting to HOST [IP] port 22. 8debug1: Connection established. 9debug1: key_load_public: No such file or directory 10debug1: identity file /Users/USER/.ssh/id_rsa type -1 11debug1: key_load_public: No such file or directory 12debug1: identity file /Users/USER/.ssh/id_rsa-cert type -1 13debug1: key_load_public: No such file or directory 14debug1: identity file /Users/USER/.ssh/id_dsa type -1 15debug1: key_load_public: No such file or directory 16debug1: identity file /Users/USER/.ssh/id_dsa-cert type -1 17debug1: key_load_public: No such file or directory 18debug1: identity file /Users/USER/.ssh/id_ecdsa type -1 19debug1: key_load_public: No such file or directory 20debug1: identity file /Users/USER/.ssh/id_ecdsa-cert type -1 21debug1: key_load_public: No such file or directory 22debug1: identity file /Users/USER/.ssh/id_ed25519 type -1 23debug1: key_load_public: No such file or directory 24debug1: identity file /Users/USER/.ssh/id_ed25519-cert type -1 25debug1: Enabling compatibility mode for protocol 2.0 26debug1: Local version string SSH-2.0-OpenSSH_6.9 27debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1 28debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 29debug1: Authenticating to HOST:22 as 'git' 30debug1: SSH2_MSG_KEXINIT sent 31debug1: SSH2_MSG_KEXINIT received 32debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none 33debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none 34debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 35debug1: Server host key: ssh-rsa SHA256:KEY 36debug1: Host 'HOST' is known and matches the RSA host key. 37debug1: Found key in /Users/USER/.ssh/known_hosts:3 38debug1: SSH2_MSG_NEWKEYS sent 39debug1: expecting SSH2_MSG_NEWKEYS 40debug1: SSH2_MSG_NEWKEYS received 41debug1: Roaming not allowed by server 42debug1: SSH2_MSG_SERVICE_REQUEST sent 43debug1: SSH2_MSG_SERVICE_ACCEPT received 44debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic 45debug1: Next authentication method: publickey 46debug1: Offering RSA public key: /Users/USER/.ssh/id_rsa 47debug1: Server accepts key: pkalg ssh-rsa blen 279 48debug1: Authentication succeeded (publickey). 49Authenticated to HOST ([IP]:22). 50debug1: channel 0: new [client-session] 51debug1: Requesting no-more-sessions@openssh.com 52debug1: Entering interactive session. 53packet_write_wait: Connection to IP: Broken pipe

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

/var/log/secure を見ると、git ユーザーで認証後、/home/git/ に chroot できないようです。

手元の環境で "gitlab-ctl reconfigure" すると、git ユーザーが作成されて、ホームディレクトリは /var/opt/gitlab となりました。公開鍵はおそらく /var/opt/gitlab/.ssh/authorized_keys に登録されていると思います。
git ユーザーのホームディレクトリは変更していないですよね。もし、変更していたら認証に失敗するはずですし。

sshd 側(/etc/ssh/sshd_config)で以下のような設定をしていませんでしょうか。

ChrootDirectory /home/git

投稿2015/10/25 11:44

編集2015/10/25 11:48
TaichiYanagiya

総合スコア12146

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2015/10/25 15:55

/etc/ssh/sshd_configを確認したところ下記のようになっていて、おそらくデフォルトのままです。 #ChrootDirectory none gitユーザーのホームディレクトリをfingerで確認したところ、/var/opt/gitlabになっていました。実行結果は下記の通りです。 Login: git Name: Directory: /var/opt/gitlab Shell: /bin/sh Never logged in. No mail. No Plan. /var/opt/gitlab/.ssh/authorized_keysを確認したところ、公開鍵は正しく登録されていました。 なぜ/home/gitにアクセスしに行ってしまうのでしょうか?
TaichiYanagiya

2015/10/26 02:26

該当のログは、sshd_config に "ChrootDirectory /home/git" あるいは "ChrootDirectory /home/%u" と設定されている場合にしか出ないと思うのですが、設定されていないようですね。ちょっと、わかりません。 考えにくいですが、"sshd -f (設定ファイル)" で別の設定ファイルで起動しているとか、"-o ChrootDirectory=/home/%u" で設定を上書きしているとか。 他の一般ユーザーで SSH ログインした場合は chroot 環境にならないのですよね?
退会済みユーザー

退会済みユーザー

2015/10/26 04:30 編集

根本的な解決方法ではないですが、 Match User git ChrootDirectory none にて、解決することができました。 ありがとうございました。 追記: 他の一般ユーザーでログインしてもchroot環境にならないことを確認しました。
guest

0

鍵の生成と登録は済んでいるでしょうか?
済んでいたら、私の回答はスルーしちゃってください。


使用しているOSがWindowsであれば、
Cygwinをインストールし、sshを導入すると楽です。
鍵の生成 - OSDN
手順としては、そう変わりません

鍵の生成→公開鍵をサイトに登録→ssh接続の認証に秘密鍵を使用

検索キーワード
「GitLab ssh 接続」
「GitLab 公開鍵 登録」

投稿2015/10/23 22:24

Ryo

総合スコア507

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2015/10/23 22:27

鍵の生成と登録は既に行っています。 説明不足ですいません。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問