2013-07-23 32 views
0

的〜/ .ssh/config中包含多個SSH密鑰Capistrano的部署Github的SSH配置失敗,沒有找到話說庫

# User_A 
Host github.com-User_A 
HostName github.com 
User git 
PreferredAuthentications publickey 
IdentityFile ~/.ssh/id_rsa 
IdentitiesOnly yes 

# User_B 
Host github.com-User_B 
HostName github.com 
User git 
PreferredAuthentications publickey 
IdentityFile ~/.ssh/id_rsa_user_b 
IdentitiesOnly yes 

# http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods 
Host example.com 
IdentityFile ~/.ssh_keys/example_env.pem 
ForwardAgent yes 

在本地機器上:

$ ssh -T [email protected] 
    Hi User_B! You've successfully authenticated, but GitHub does not provide shell access. 

在遠程機器

~$ ssh [email protected] 

    [[email protected] ~]$ ssh -T [email protected] 
    Hi User_A! You've successfully authenticated, but GitHub does not provide shell access. 

備註:

  • SSH-添加-l顯示所有提到的鍵入伍
  • deploy.rb包含:

    set :repository, "[email protected]_B:<REPO_NAME>" 
    
    ssh_options[:forward_agent] = true 
    

我試圖部署使用Capistrano的到Amazon EC2實例我有關申請我已經使用ssh-add將.pem文件添加到本地計算機上,並且可以看到輸入爲ssh-add -l。但是,在部署時遇到以下錯誤:

** [example.com :: err] ERROR: Repository not found. 
** fatal: The remote end hung up unexpectedly 

以下是我的帽子部署命令的完整輸出:

$ cap bat deploy 

    triggering load callbacks 
* executing `bat' 
    triggering start callbacks for `deploy' 
* executing `multistage:ensure' 
* executing `deploy' 
* executing `deploy:update' 
    ** transaction: start 
* executing `deploy:update_code' 
    updating the cached checkout on all servers 
    executing locally: "git ls-remote [email protected]_B:<REPO_NAME> <BRANCH_NAME>" 
    command finished in 6296ms 
* executing "if [ -d /srv/<APP_NAME>/shared/cached-copy ]; then cd /srv/<APP_NAME>/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard df84fadff305e1729991caddde47f6802e424d57 && git clean -q -d -x -f; else git clone -q [email protected]_B:<REPO_NAME> /srv/<APP_NAME>/shared/cached-copy && cd /srv/<APP_NAME>/shared/cached-copy && git checkout -q -b deploy df84fadff305e1729991caddde47f6802e424d57; fi" 
    servers: ["example.com"] 
    [example.com] executing command 
    ** [example.com :: err] ERROR: Repository not found. 
    ** fatal: The remote end hung up unexpectedly 
    command finished in 3811ms 
    *** [deploy:update_code] rolling back 
* executing "rm -rf /srv/<APP_NAME>/releases/20130723222237; true" 
    servers: ["example.com"] 
    [example.com] executing command 
    command finished in 477ms 
    failed: "sh -c 'if [ -d /srv/<APP_NAME>/shared/cached-copy ]; then cd /srv/<APP_NAME>/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard df84fadff305e1729991caddde47f6802e424d57 && git clean -q -d -x -f; else git clone -q [email protected]_B:<REPO_NAME> /srv/<APP_NAME>/shared/cached-copy && cd /srv/<APP_NAME>/shared/cached-copy && git checkout -q -b deploy df84fadff305e1729991caddde47f6802e424d57; fi'" on example.com 

所以我想這個錯誤是由於多個SSH密鑰之間發生衝突造成越來越本地機器USER_B(即檢測出誰是成員)作爲默認值使用,但在遠程計算機上使用User_A(無權訪問存儲庫)。

如果我的假設是正確的,任何人都可以幫助我解決這個問題嗎?代理轉發時可以使用特定用戶配置嗎?如果不是,那麼解決方案是什麼?

謝謝。

回答

0

好吧,好像它在〜/ .ssh/config中列出鍵的順序很重要。

最初,它是

# User_A 
    Host github.com-User_A 
    HostName github.com 
    User git 
    PreferredAuthentications publickey 
    IdentityFile ~/.ssh/id_rsa 
    IdentitiesOnly yes 

    # User_B 
    Host github.com-User_B 
    HostName github.com 
    User git 
    PreferredAuthentications publickey 
    IdentityFile ~/.ssh/id_rsa_user_b 
    IdentitiesOnly yes 

    # http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods 
    Host example.com 
    IdentityFile ~/.ssh_keys/example_env.pem 
    ForwardAgent yes 

後來我這樣做:

# User_B 
    Host github.com-User_B 
    HostName github.com 
    User git 
    PreferredAuthentications publickey 
    IdentityFile ~/.ssh/id_rsa_user_b 
    IdentitiesOnly yes 

    # User_A 
    Host github.com-User_A 
    HostName github.com 
    User git 
    PreferredAuthentications publickey 
    IdentityFile ~/.ssh/id_rsa 
    IdentitiesOnly yes 


    # http://serverfault.com/questions/400633/capistrano-deploying-to-different-servers-with-different-authentication-methods 
    Host example.com 
    IdentityFile ~/.ssh_keys/example_env.pem 
    ForwardAgent yes 

但這樣做,我沒有重新啓動機器後,因此變化並不生效。

今天上午後,我開始我的機器上張貼上述問題,我發現,這是工作後:

在本地機器上:

$ ssh -T [email protected] 
    Hi User_B! You've successfully authenticated, but GitHub does not provide shell access. 

在遠程機器

$ ssh -T [email protected] 
    Hi User_B! You've successfully authenticated, but GitHub does not provide shell access. 

希望這有助於別人也會遇到類似的問題。

謝謝。

+0

你也可以輸入ssh -T github.com-User來測試配置 –