ubutnu12.04下设置bitbucket的公钥和私钥

参考自官网:https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git

一.安装ssh

 

sudo apt-get install ssh-client

二.创建公钥和私钥

 

 

ssh-keygen

三.创建config文件,内容如下

 

 

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa

 

 

四.关闭shell,新打开一个shell,编辑.bashrc,添加如下

 

SSH_ENV=$HOME/.ssh/environment
   
# start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."
    # spawn ssh-agent
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add
}
   
if [ -f "${SSH_ENV}" ]; then
     . "${SSH_ENV}" > /dev/null
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

 

 

五.设置bitbucket上的公钥

  1. Open a browser and log into Bitbucket.
  2. Choose avatar > Manage Account from the menu bar.
    The system displays the Account settings page.
  3. Click SSH keys.
    The SSH Keys page displays. It shows a list of any existing keys. Then, below that, a dialog for labeling and entering a new key.
  4. In your terminal window, cat the contents of the public key file.
    For example:

    cat ~/.ssh/id_rsa.pub
  5. Select and copy the key output in the clipboard.
    If you have problems with copy and paste, you can open the file directly with Notepad. Select the contents of the file (just avoid selecting the end-of-file character).

  6. Back in your browser, enter a Label for your new key, for example, Default public key.

  7. Paste the copied public key into the SSH Key field.
  8. Click the Add key button:
  9. The system adds the key to your account.
  10. Return to the terminal window and verify your configuration by entering the following command.

    The command message tells you which Bitbucket account can log in with that key. 

    conq: logged in as tutorials.
    You can use git or hg to connect to Bitbucket. Shell access is disabled.
  11. Verify that the command returns your account name.

六.配置仓库使用ssh协议

编辑项目下的.git/config文件

修改url为

[remote "origin"]
  fetch = +refs/heads/*:refs/remotes/origin/*
  url = [email protected]:newuserme/bb101repo.git

 

七.测试OK

 

 

 

 

 

你可能感兴趣的:(公钥和私钥)