【问题标题】:Not able to connect to bitbucket using git ssh in EC2 Ubuntu instance无法在 EC2 Ubuntu 实例中使用 git ssh 连接到 bitbucket
【发布时间】:2020-03-05 07:53:14
【问题描述】:

我正在尝试在 ubuntu EC2 实例上使用 SSH 连接 git。

我尝试了以下步骤,但出现公钥错误。

  • 使用命令 ssh-keygen 生成 SSH 并将该密钥添加到 bitbucket 中。
  • 已编辑 ~username/.ssh/authorized_keys 并添加了生成的密钥。
  • 当我运行命令 ssh -T git@bitbucket.org,我看到以下结果,

    logged in as user-name
    
    You can use git or hg to connect to Bitbucket. Shell access is disabled
    
  • 如果我在项目目录中执行 git pull ,则会出现错误

    git@bitbucket.org: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

帮助我摆脱这个错误。

注意:我尝试了以下解决方案,但没有成功。 git push origin master: permission denied (public key) error

注意(已更新) :: 它可以在我的本地机器(Windows)中使用 SSH 密钥。

【问题讨论】:

  • 您的密钥是否在ssh-add -L 中列出?
  • 是的,它显示了我的钥匙。

标签: git ubuntu amazon-ec2 ssh bitbucket


【解决方案1】:

我尝试了以下解决方案,它奏效了。

sudo su - root  # switch to root user
cat ~/.ssh/id_rsa.pub  # create if not already existing
sudo su - ubuntu  # switch back to normal user

这是来自Unable to add ssh-key of EC2 instance to bitbucket account

【讨论】:

    【解决方案2】:

    您可能需要更改密钥和文件夹的权限。

    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    

    您可能还需要更改主目录的权限并删除组和其他人的写入权限。

    chmod go-w ~
    

    This帮我回答了你的问题。

    【讨论】:

    • 如果关键权限是问题,那么这将导致ssh git@bitbucket.org 测试出错。
    • @amsh 它不起作用,我仍然收到公钥错误。
    猜你喜欢
    • 2022-10-14
    • 2020-08-07
    • 2011-10-30
    • 2020-03-13
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多