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, 现在进行远程操作,摆脱输入密码的烦恼。
博客介绍了使用 SSH key 在电脑和 Git @ OSC 间建立安全加密连接的方法。包括生成 sshkey、查看 public key 并添加到 GitHub,若 GIT 的 remote url 为 HTTPS 需改成 SSH 协议地址,完成后可进行远程操作且无需输入密码。
1003

被折叠的 条评论
为什么被折叠?



