尝试使用Capistrano进行部署但是我的远程计算机上的ssh

编程入门 行业动态 更新时间:2024-10-25 06:24:02
尝试使用Capistrano进行部署但是我的远程计算机上的ssh-agent没有加载我的身份,因此git命令失败;(trying to deploy using Capistrano but ssh-agent on my remote machine doesn't keep my identity loaded so the git command fails; why?)

我浏览了一些关于如何准备使用Capistrano的文档,其中包括Capistrano网站的“身份验证和授权”。

当我做这个命令时,所有人都在花哨

me@localhost $ ssh deploy@one-of-my-servers.com 'hostname; uptime'

但是......当我遇到这个命令时

me@localhost $ ssh -A deploy@one-of-my-servers.com 'git ls-remote git@bitbucket.org:team/application.git

我害怕了

Permission denied (publickey).

我决定直接作为部署用户ssh到服务器并从那里尝试我的命令,但后来我被问到我的密码:

me@localhost:~$ ssh deployer@server.com ... bunch of logon information ... deployer@server:~$ git ls-remote git@bitbucket.org:team/application.git Enter passphrase for key '/home/deployer/.ssh/id_rsa':

我输入了密码并得到了bitbucket的回复。 现在我不明白为什么我被问到我的密码短语,因为ssh-agent应该加载我的身份,并且所有人应该对deployer和bitbuckt都很好。 我决定检查ssh-agent是否通过运行加载了我的身份

ssh-add -l

但后来我得到了

Could not open a connection to your authentication agent.

什么? 好吧,然后我启动了ssh-agent并确保通过执行此操作来加载我的身份

deployer@server:~$ eval "$(ssh-agent)" Agent pid 30113 deployer@server:~$ ssh-add -l The agent has no identities. deployer@server:~$ ssh-add Enter passphrase for /home/deployer/.ssh/id_rsa: Identity added: /home/deployer/.ssh/id_rsa (/home/deployer/.ssh/id_rsa) deployer@server:~$ ssh-add -l 2048 6c:87:f9:e1:71:75:0d:1c:cf:8d:d8:a8:06:fc:70:e7 /home/deployer/.ssh/id_rsa (RSA)

现在我可以从bitbucket做我的远程列表,而不必输入我的密码

deployer@server:~$ git ls-remote git@bitbucket.org:team/application.git f25db5c4691531c8ad27882c74d9668de66f795f HEAD 97a68f4f6cbffd0c320b37891ffdda57931146f4 refs/heads/deployer f25db5c4691531c8ad27882c74d9668de66f795f refs/heads/master deployer@server:~$

现在我很高兴退出服务器并再次尝试从我的本地机器

deployer@server:~$ exit logout Connection to server.com closed. me@localhost:~$ ssh deployer@server.com 'git ls-remote git@bitbucket.org:team/application.git' Permission denied (publickey). fatal: The remote end hung up unexpectedly

??? 我的问题就在于......现在你能看到我哪里出错吗?

I went through the a few documentation on how to prepare for using Capistrano and among those was the "authentication and authorization" from the Capistrano web site.

All was going dandy when I did this command

me@localhost $ ssh deploy@one-of-my-servers.com 'hostname; uptime'

but.. when I come across this command

me@localhost $ ssh -A deploy@one-of-my-servers.com 'git ls-remote git@bitbucket.org:team/application.git

I got a dreaded

Permission denied (publickey).

I decided to ssh to the server directly as the deployment user and try my command from there but then I was asked for my passphrase:

me@localhost:~$ ssh deployer@server.com ... bunch of logon information ... deployer@server:~$ git ls-remote git@bitbucket.org:team/application.git Enter passphrase for key '/home/deployer/.ssh/id_rsa':

I entered the passphrase and got the response from bitbucket. Now I didn't understand why I was asked for my passphrase becuase the ssh-agent should have my identy loaded and all should be good with deployer and bitbuckt. I decided to check if ssh-agent had my identity loaded by running

ssh-add -l

but then I got

Could not open a connection to your authentication agent.

what? ok, then I started the ssh-agent and made sure my identity was loaded by doing this

deployer@server:~$ eval "$(ssh-agent)" Agent pid 30113 deployer@server:~$ ssh-add -l The agent has no identities. deployer@server:~$ ssh-add Enter passphrase for /home/deployer/.ssh/id_rsa: Identity added: /home/deployer/.ssh/id_rsa (/home/deployer/.ssh/id_rsa) deployer@server:~$ ssh-add -l 2048 6c:87:f9:e1:71:75:0d:1c:cf:8d:d8:a8:06:fc:70:e7 /home/deployer/.ssh/id_rsa (RSA)

and now I could do my remote listing from bitbucket just fine without having to enter my passphrase

deployer@server:~$ git ls-remote git@bitbucket.org:team/application.git f25db5c4691531c8ad27882c74d9668de66f795f HEAD 97a68f4f6cbffd0c320b37891ffdda57931146f4 refs/heads/deployer f25db5c4691531c8ad27882c74d9668de66f795f refs/heads/master deployer@server:~$

now I was happy and logged out of the server and tried again from my local machine

deployer@server:~$ exit logout Connection to server.com closed. me@localhost:~$ ssh deployer@server.com 'git ls-remote git@bitbucket.org:team/application.git' Permission denied (publickey). fatal: The remote end hung up unexpectedly

??? There lies my problem... now can you see where I'm going wrong?

最满意答案

您可以登录一次以启动ssh-agent并将密钥(ssh-add)加载到代理中。 将ssh-agent的输出保存在某个文件中。

当您远程登录git时,使用保存的信息通过bashrc或其他启动脚本设置SSH_AUTH_SOCK和SSH_AGENT_PID。 您不需要新的ssh-agent。 你需要指向已经拥有密钥的那个。

You can login once to start the ssh-agent and load your keys (ssh-add) into the agent. Save the output of ssh-agent in some file.

When you login remotely for git purpose, set SSH_AUTH_SOCK and SSH_AGENT_PID through your bashrc or some other startup script using the saved info. You do not want a new ssh-agent. You need to point to the same one that already has the keys.

更多推荐

本文发布于:2023-07-21 09:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:机上   Capistrano   ssh

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!