SSH key 可以让你在你的电脑和 Git @ OSC 之间建立安全的加密连接。
你可以按如下命令来生成sshkey
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"# Creates a new ssh key using the provided email
# Generating public/private rsa key pair...
# Generating public/private rsa key pair...
查看你的public key,并把他添加到 GitHub上。
cat ~/.ssh/id_rsa.pub# ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....
AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....
添加后,在终端(Terminal)中输入
ssh -T git@git.oschina.net
若返回
Welcome to Git@OSC, yourname!
则证明添加成功。
如果你的GIT的remote url使用的是HTTPS的话,还需要改成SSH协议地址。
$ git remote -v
origin https://github.com/someaccount/someproject.git (fetch)
origin https://github.com/someaccount/someproject.git (push)
origin https://github.com/someaccount/someproject.git (fetch)
origin https://github.com/someaccount/someproject.git (push)
可以看到使用的是HTTPS。
用浏览器登陆你的github,在上面可以看到你的ssh协议相应的url。类似如下
git@git.oschina.net:youaccountname/projectname.git
使用 git remote set-url 调整你的url。
git remote set-url origin git@git.oschina.net:youaccountname/projectname.git
完后,可以再使用remote -v再次查看是否修改成功。
至此,所有的都完成了。
你可以用git fetch, git pull , git push, 现在进行远程操作,摆脱输入密码的烦恼。