bitbucket通过SSH密钥连接

序言

项目托管服务较好的当属 GitHub 和 Bitbucket 了, 二者都支持 Git 版本控制。二者最大的区别是:

    1. GitHub 很火正常访问,Bitbucket 最近访问有点问题(...)
    1. GitHub 私有库需要付费,Bitbucket 私有库免费
    1. GitHub 只支持 Git,Bitbucket 同时支持 Mercurial

废话不多说,开始配置

Step 1: 检查SSH密钥
> cd ~/.ssh

如果返回 "No such file or directory" 转 Step 2. 否则说明你已经有一个密匙对,转到 Step 3.

Step 2: 生成新的SSH密钥
> ssh-keygen -t rsa -C "your_email@example.com"

使用你的邮件创建一个新的 SSH 密匙标签,将会生成 ~/.ssh/id_rsa 文件, 用于存储你的密匙。

现在,你需要输入一个密码:

Enter passphrase (empty for no passphrase): [输入一个密码]
Enter same passphrase again: [重新输入密码]

一般没有特殊需要,直接回车即可。

你将看到一下信息:

Your identification has been saved in /home/you_username/.ssh/id_rsa.
Your public key has been saved in /home/you_username/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
Step 3-1: 复制 SSH 密匙

安装复制工具:

> sudo zypper install xclip

根据自己的系统选择 zypper/yum/apt-get

复制 SSH 密匙到剪切板:

> xclip -sel clip < ~/.ssh/id_rsa.pub

当然你也可以不安装 xclip,使用 cat 命令,输入到终端再复制。

Step 3-2: 添加 SSH 密匙到 GitHub
1. 点击右上角 "Account Settings" 设置图标
2. 点击左侧 "SSH Keys"
3. 点击 "Add SSH key"
4. 粘贴你的密匙到 "Key" 文本区
5. 点击 "Add key"
6. 确认操作输入你的 GitHub 密码
Step 3-3: 添加 SSH 密匙到 Bitbucket
1. 点击右上角"用户头像"
2. 点击下拉菜单中的 "Manage account"
3. 点击左侧 "SSH keys"
4. 点击 "Add key"
5. 粘贴你的密匙到 "Key" 文本区
6. 点击 "Add key"

Bitbucket 的 Account settings 中可以设置为中文的。

Step 4: 测试连接

GitHub:

> ssh -T git@github.com

Bitbucket:

> ssh -T git@bitbucket.org

你可能会看到这样的提示:

The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?

输入 yes 即可

GitHub 成功提示:

Hi you_username! You've successfully authenticated, but GitHub does not
provide shell access.

Bitbucket 成功提示:

conq: logged in as you_username.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

如果出现 access denied 一般是添加的 key 的问题,请检查本地 key 和线上 key 是否相同, 或参考 Error: Permission denied (publickey)

到此你就可以使用 git clone 你的项目,提交更改了。

注:Bitbucket 使用 ssh 方式克隆, 如:git clone git@bitbucket.org:you_username/project.git

参考

本文大部分内容翻译自下面的连接

GitHub Help: https://help.github.com/articles/generating-ssh-keys
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
为了在GitLab上配置公共SSH密钥,你可以按照以下步骤进行操作: 1. 首先,确保你已经生成了SSH密钥对。你可以使用命令`ssh-keygen -t rsa`生成密钥对。生成的密钥将包括一个私钥(id_rsa)和一个公钥(id_rsa.pub)。 2. 打开GitLab并登录到你的账户。 3. 在页面右上角的用户菜单中,选择"Settings"。 4. 在左侧菜单中,选择"SSH Keys"。 5. 在"Key"字段中,粘贴你的公钥(即id_rsa.pub文件的内容)。 6. 可选:在"Title"字段中,为你的密钥添加一个可识别的名称。 7. 点击"Add key"按钮以添加你的公钥。 8. GitLab将验证并添加你的公钥,你现在就可以使用SSH来进行GitLab的远程操作了。 请注意,以上步骤是为了在GitLab上配置公共SSH密钥。如果你需要在其他代码托管平台(如GitHub或Bitbucket)上进行配置,可以参考它们的相应文档或设置页面的指导。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [代码管理git生成ssh key (公钥私钥)配置GitLab](https://blog.csdn.net/qq_43064422/article/details/125102263)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [ssh-git:桌面应用程序,用于管理Github,Bitbucket和Gitlab帐户的SSH密钥](https://download.csdn.net/download/weixin_42134285/18410307)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值