使用SSH协议,能够链接到远程服务器和服务并进行身份验证。 使用SSH密钥,能够链接到GitHub,而无需在每次访问时都提供用户名或密码。git
打开 Git Bash 并输入如下命令(用你的GitHub电子邮件地址替换命令中的电子邮件地址)github
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
当看到如下命令提示时,按回车,就会把文件存在默认的路径下(能够改路径,改路径后,在后边的操做须要额外的操做,这里我不改路径)服务器
> Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):
当看到如下命令提示时,输入自定义密码(不是GitHub密码),这个密码在链接GitHub时会用到,好比pull、push的时候ssh
> Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
确保生成成功fetch
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
将新的SSH密钥添加到GitHub账户后,就能够从新配置任何本地仓库以使用SSH。网站
复制SSH Keyurl
clip < ~/.ssh/id_rsa.pub
在GitHub网站页面,点击右上角的我的头像,点击Settingscode
点击左侧栏目中的“SSH and GPG keys”blog
点击右上角的“New SSH key”ip
在打开的页面中的Title中填入这个key的描述,如Company Computer;在Key中粘贴复制的SSH Key;而后点击Add SSH Key按钮
在弹出的页面中输入Github密码
完成添加
git remote -v > origin https://github.com/USERNAME/REPOSITORY.git (fetch) > origin https://github.com/USERNAME/REPOSITORY.git (push)
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
git remote -v # Verify new remote URL > origin git@github.com:USERNAME/REPOSITORY.git (fetch) > origin git@github.com:USERNAME/REPOSITORY.git (push)
到此,切换完成。后续的pull、push等操做就会使用SSH了
从新生成一个SSH Key,添加到github便可