DunanSu 2014-08-02
参考自官网: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上的公钥
In your terminal window, cat
the contents of the public key file.
For example:
cat ~/.ssh/id_rsa.pub
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).
Back in your browser, enter a Label for your new key, for example, Default public key
.
Return to the terminal window and verify your configuration by entering the following command.
ssh -T [email protected]
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.
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