2011-10-28 5 views
7

これはおそらくdupではありません。私はStackOverflowの多くの同様の問題を読んだが、この問題は読んでいない。Github複数のアカウント1台のコンピュータに1つのアカウントが常に表示されます

私はUbuntu Linuxで複数のgitアカウントを使用しようとしており、2番目のアカウントからプッシュしようとするたびに、最初のアカウントのユーザー名を使用していると思います。

$ git push -u origin master 
ERROR: Permission to <act2>/<repo>.git denied to <act1>. 

まず、複数のSSHキー方式を試しました。上記のエラーが発生したら、ローカルマシン上に全く新しいユーザーを作成し、そのユーザーとしてログインし、ローカルrepo(最初のプッシュ)を再作成して再試行しました。同じエラー。私のローカル.configはユーザーを表示し、〜/ .gitconfigも表示します。

アイデア?

私が行います @localhost sshのその後のssh -vvv -T [email protected]

私はこの興味深い出力を得ます。私のアカウントで鍵が見つかったようです。しかし、どういうわけか私のアカウントの鍵を使っています。本当にアクセスできないはずです。


debug1: Host 'github.com' is known and matches the RSA host key. 
debug1: Found key in /home//.ssh/known_hosts:1 
debug2: bits set: 513/1024 
debug1: ssh_rsa_verify: signature correct 
debug2: kex_derive_keys 
debug2: set_newkeys: mode 1 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug3: Wrote 16 bytes for a total of 1015 
debug2: set_newkeys: mode 0 
debug1: SSH2_MSG_NEWKEYS received 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug3: Wrote 48 bytes for a total of 1063 
debug2: service_accept: ssh-userauth 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug2: key: 
debug2: key: 
debug2: key: /home//.ssh/identity ((nil)) 
debug2: key: /home//.ssh/id_rsa() 
debug2: key: /home//.ssh/id_dsa ((nil)) 
debug3: Wrote 64 bytes for a total of 1127 
debug1: Authentications that can continue: publickey 
debug3: start over, passed a different list publickey 
debug3: preferred gssapi-keyex,gssapi-with-mic,gssapi,publickey,keyboard-interactive,password 
debug3: authmethod_lookup publickey 
debug3: remaining preferred: keyboard-interactive,password 
debug3: authmethod_is_enabled publickey 
debug1: Next authentication method: publickey 
debug1: Offering public key: 
debug3: send_pubkey_test 
debug2: we sent a publickey packet, wait for reply 
debug3: Wrote 368 bytes for a total of 1495 
debug1: Authentications that can continue: publickey 
debug1: Offering public key: 
debug3: send_pubkey_test 
debug2: we sent a publickey packet, wait for reply 
debug3: Wrote 368 bytes for a total of 1863 
debug1: Remote: Forced command: gerve 
debug1: Remote: Port forwarding disabled. 
debug1: Remote: X11 forwarding disabled. 
debug1: Remote: Agent forwarding disabled. 
debug1: Remote: Pty allocation disabled. 
debug1: Server accepts key: pkalg ssh-rsa blen 277 
debug2: input_userauth_pk_ok: fp 
debug3: sign_and_send_pubkey 
debug3: Wrote 640 bytes for a total of 2503 
debug1: Remote: Forced command: gerve 
debug1: Remote: Port forwarding disabled. 
debug1: Remote: X11 forwarding disabled. 
debug1: Remote: Agent forwarding disabled. 
debug1: Remote: Pty allocation disabled. 
debug1: Authentication succeeded (publickey). 
debug1: channel 0: new [client-session] 
debug3: ssh_session2_open: channel_new: 0 
debug2: channel 0: send open 
debug1: Requesting [email protected] 
debug1: Entering interactive session. 
debug3: Wrote 128 bytes for a total of 2631 
debug2: callback start 
... 
+0

VM全体(act1は存在しません)で動作しましたが、うまくいきました...しかし、それは間違いなく理想的です:-( – AndrewStone

答えて

9

これは、ssh-agentがファイルを削除することもできます(ファイルを削除することもできますが、キャッシュがクリアされるまでsshが正常に接続できる)ので、キャッシュされた鍵はIdentityFileで指定されたものよりも優先されます。あなたは実行することにより、キャッシュされたファイルを見ることができます。

ssh-add -l 

あなたは、接続ごとの.ssh/configの中で「はい」IdentitiesOnlyを含むことにより、キャッシュを無視するのssh-agentを強制することができます

Host github 
    HostName github.com 
    User git 
    IdentityFile ~/.ssh/id_rsa 
    IdentitiesOnly yes 

Host github-work 
    HostName github.com 
    User git 
    IdentityFile ~/.ssh/id_dsa_work 
    IdentitiesOnly yes 

をここに詳しい情報:http://sealedabstract.com/code/github-ssh-with-multiple-identities-the-slightly-more-definitive-guide/

これを発見するまでにかなりの時間がかかりました。

+0

これは、巨大な、巨大なヘルプフィルです。これはすぐに私の問題を解決しました。 – AKWF

0

.gitフォルダーとその内容のアクセス許可を確認してください。 ssh github.com -vvvvでgithubに渡されているSSH鍵を確認してください。

+0

ssh [email protected] -vvvvは "Hi " sshが私の他のユーザの行為に到達してそれを見ている理由で、なぜ – AndrewStone

+0

が表示されたのかを知るために、すべての出力を掘り下げています。debug2:key:/ home/ /.ssh/id_rsaと "リモート:forcedコマンド:gerve " – AndrewStone

+0

あなたは間違ったホームディレクトリを持っているかもしれませんが、どうすればいいでしょうか? –

3

この回答に私の前提を述べると、あなたが本当にやりたいことは、別のGitHubユーザーとして識別されているGitHubにプッシュできるように、質問タイトルから聞こえます。

この場合、SSH経由で異なるGitHubユーザーにプッシュするために、システムに複数のユーザーを作成しないでください。これを行う正しい方法は、github.com~/.ssh/configに異なるIDファイルを指定する2つのエイリアス(as described here)を設定することです。たとえば、あなたが~/.ssh/configで次のかもしれません。

Host github-act1 
    HostName github.com 
    User git 
    IdentityFile /home/whoever/.ssh/id_rsa.act1 

Host github-act2 
    HostName github.com 
    User git 
    IdentityFile /home/whoever/.ssh/id_dsa.act2 

を次に、あなたのリポジトリに2つのリモコンを追加することができます。

git add remote act1 [email protected]:whoever/whatever.git 
git add remote act2 [email protected]:whoever/whatever.git 

を次に、あなたが行うことができます1人のユーザーとしてプッシュする場合:

git push act1 master 

...または第二のアカウントなど:

git push act2 master 
+0

はい、私はその方法を最初に試みました。いくつかのssh設定問題がありました... – AndrewStone

+0

@AndrewStone:2人目のユーザーとしてどのようにログインしていますか? 2人目のユーザーとしてログインしていますか? –

+0

ssh @localhost。/home/と表示されます。 4日間の停電に遅れて申し訳ありません – AndrewStone

0
debug2: key: 
debug2: key: 
debug2: key: /home//.ssh/identity ((nil)) 
debug2: key: /home//.ssh/id_rsa() 
debug2: key: /home//.ssh/id_dsa ((nil)) 

それはひどく疑わしいです。あなたのホームディレクトリはなぜちょうど/home/ですか?複数のユーザが同じホームディレクトリを持っている場合、sshが両方のユーザに同じ鍵を見つけても驚くことはありません。

echo $HOME 

の結果を各ユーザーとしてログインして確認してください。彼らは別のディレクトリを指すべきです。

関連する問題