无法使用 SSH 密钥从远程服务器访问 bitbucket 以对存储库中的最新代码执行 git 拉取

Unable to access bitbucket from remote server using SSH key to perform a git pull on latest code in repository

我正在尝试使用 git pull 命令将 bitbucket 上的最新代码拉入开发 (Ubuntu) 服务器。 git pull 命令尝试通过 SSH 连接以 root 用户身份访问 bitbucket,但也要求提供与 SSH 相关的释义。 Ubuntu 服务器上的 root/.ssh 文件夹包含 id_rsa 和 id_rsa.pub 文件,但我无法将公钥从 id_rsa.pub 添加到 bitbucket,因为显然那个密钥正在被别人使用。我也不知道与此 SSH 密钥有关的释义。那么几个问题:

  1. 当我无法将 SSH public 密钥添加到 bitbucket 时,远程服务器如何通过 SSH 连接到 bitbucket 存储库?
  2. 我是否应该在 Ubuntu 服务器中创建一个新的 SSH 密钥并尝试将其(public 密钥部分)添加到 bitbucket,然后使用新密钥访问 bitbucket?
  3. 如果我没有输入 git pull 命令后服务器不断提示我输入的释义,那么从存储库中提取代码的最佳方法是什么?以下是我能想到的一些方法,但感谢有关最佳方法的指导:

A) 创建新的 SSH 密钥(有或没有释义,尽管我认为有释义更安全),将新的 public 密钥添加到 bitbucket,然后尝试通过 SSH 从 bitbucket 中提取代码。我认为服务器仍会尝试以 root 用户身份访问 bitbucket,而不是我用来登录服务器的用户名。这当然需要我首先获得对 /root 和 /root/.ssh 文件夹的读写执行权限(在我的服务器上,我禁用了 root 用户的登录能力)。

B) 使用现有的 SSH 密钥(如上所述,我无法将其添加到 bitbucket)以不同用户(不是 root 用户,但可能是我用来登录 Ubuntu 服务器?)为了使用这种方法从 bitbucket 存储库中提取代码,我是否首先必须在 Ubuntu 服务器上我的主目录 (/home/myusername/.ssh) 下设置一个 SSH 密钥?

How is the remote server connecting to the bitbucket repository via SSH when I'm unable to add the SSH public key to bitbucket?

初始化与 Bitbucket 的连接时使用 SSH 握手协议,这涉及确定可以使用哪个密钥。在这种情况下,将尝试 root/.ssh 中的每个密钥,当一个被 Bitbucket 接受时,将建立一个连接(您可能有一个 root/.ssh/config 说明要使用哪个密钥,然后仅将被使用)

SSH 密钥与 Bitbucket 上的单个帐户相关联(1-1 关系),并且当给定 SSH 密钥(来自握手过程)时,Bitbucket 知道要使用哪个帐户。显然,有人已经在使用这个密钥了。

Should I instead create a new SSH key in the Ubuntu server and try to add that (the public key part) to bitbucket, then access bitbucket using the new key?

是的,您需要为 Bitbucket 上的每个帐户至少提供一个密钥,以便从您的开发服务器访问 Bitbucket。

If I don't have the paraphrase that the server keeps prompting me to enter after typing the git pull command, what's the best approach to pulling code from the repository?

不清楚您为什么使用 root 访问 Bitbucket,但如果可能的话,我会在主目录中拥有自己的密钥 /home/myusername/.ssh(并在服务器上拥有自己的远程存储库克隆)。

我认为 root 是 运行 一些涉及从 Bitbucket 中提取的任务,然后您可以为其创建一个单独的 Bitbucket 帐户并为该帐户使用单独的密钥。