Github 之 SSH key的创建于配置(Windows)

最近配置了github的ssh key,翻找了大量资料后发现github官方就有相关的教程……在此翻译一下官方教程以加深印象

原文链接:https://help.github.com/categories/ssh/

Generating an SSH key(生成SSH key)

SSH密钥是来识别值得信赖的电脑的方法。您可以生成一个SSH密钥,并按照本节所述的方法将公共密钥添加到您的帐户GitHub中。

Checking for existing SSH keys(检查已存在的SSH key)

在你生成一个ssh key之前,你可以检查一下你是否已经有了ssh key:

  1. 打开Git Bash
  2. 输入
    ls -al ~/.ssh

    来查看是否有ssh key存在

  3. 检查/.ssh目录来查看是否存在公开的ssh key

一般而言,公开的ssh key的文件名为以下几种:

  • id_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub
  • id_rsa.pub

Generating a new SSH key and adding it to the ssh-agent(生成一个新的SSH key并添加到ssh-agent)

在你检查过存在的ssh key后,你可以新建一个ssh key:

  1. 打开Git Bash
  2. 输入这一串:
    ssh-keygen -t rsa -b 4096 -C "[email protected]"

    生成一个新的ssh key,使用填入的邮箱地址作为ssh key的标签,并生成RSA密钥对

  3. 看到如下提示时:
    Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

    按下回车,表示把ssh key放在默认地址

  4. 然后为ssh key设置密码:
    Enter passphrase (empty for no passphrase): [Type a passphrase]
    Enter same passphrase again: [Type passphrase again]

创建完ssh key后,你需要把它添加到ssh-agent中去:

  1. 首先保证ssh-agent启用了:

    eval "$(ssh-agent -s)"

    该指令返回进程id则表示已经启用ssh-agent

  2. 使用如下指令把ssh key添加到ssh-agent中:
    ssh-add ~/.ssh/id_rsa

Adding a new SSH key to your GitHub account(为你的github账号添加SSH key)

在把ssh key添加到ssh-agent后,你需要把ssh key添加到你的github账号中:

  1. 打开Git Bash,使用指令把ssh key复制到剪贴板:

    clip < ~/.ssh/id_rsa.pub

    如果不成功就用编辑器打开该文件直接复制内容

  2. 在github右上角点击setting

  3. 在左边选择SSH and GPG keys

  4. 点击New SSH key

  5. 在Title处为你的ssh key填入适当的标题,在Key处粘贴你复制的ssh key

  6. 点击Add SSH key

  7. 输入你的github账号密码确认此次行动

Testing your SSH connection(测试你的SSH连接)

在进行完上面一系列操作后,是时候看看你的SSH连接是否成功了:

  1. 打开Git Bash
  2. 输入以下指令:
    ssh -T [email protected]

    尝试去用ssh连接github,你可能会看到一些警告信息:

    The authenticity of host 'github.com (192.30.252.1)' can't be established.
    RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
    Are you sure you want to continue connecting (yes/no)?

    输入yes不管他就好

  3. 如果你看到一下信息:
    Hi username! You've successfully authenticated, but GitHub does not provide shell access

    则表示ssh连接成功了

  4. 如果你收到的信息是"access denied" ,那么你可以参考一下链接进行进一步处理:https://help.github.com/articles/error-permission-denied-publickey/

Changing a remote‘s URL(改变远程仓库的URL)

在设置完ssh后,你可能需要把你的远程仓库的URL从HTTPS改为SSH(SSH好处在于不用每次push都输账号密码……):

  1. 打开GIt Bash
  2. 把工作目录转到你的本地工程中
  3. 查看拥有的远程仓库:
    git remote -v
  4. 更改远程仓库的url:
    git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

    origin为仓库名,后面接的是ssh仓库地址:

  5. 查看拥有的远程仓库,看看是否修改成功:
    git remote -v

至此Github的SSH key配置大功告成,以后push再也不用每次都输入github的账号密码了~

时间: 2024-08-13 01:51:08

Github 之 SSH key的创建于配置(Windows)的相关文章

配置github的SSH key及GitHub项目上传方式一——使用终端命令行

GitHub是一个开源的大仓库,我们经常从github上下载项目进行学习和研究,下面是一个完整的步骤--往GitHub上传一个新项目. 一.注册GitHub账号 1.注册GitHub账号,地址:https://github.com 注册账户 账户选择 2.登录: 登录.png 3.登录之后的页面,是我们star其他人的一些信息,类似于QQ空间的好友状态 D2A62592-D46E-43B8-82B5-1628131CBC67.png 二.配置GitHub的SSH key 1.查看系统中是否配置过

github添加ssh key报错Key is invalid. Ensure you&#39;ve copied the file correctly

github添加ssh key的时候报错:Key is invalid. Ensure you've copied the file correctly 将秘钥复制粘贴到文本编辑器中,再粘贴复制到 github添加ssh key报错Key is invalid. Ensure you've copied the file correctly

为github添加ssh key

用git关联github上的远程仓库前需要先为github添加ssh key 一.检查本机是否生成ssh key 本地查找.ssh文件,其中id_rsa.pub中的内容就是ssh key 二.为github上的仓库添加ssh key 原文地址:https://www.cnblogs.com/2sheep2simple/p/10372391.html

我的Python成长之路---GitHub使用克隆GitHub(SSH key配置)

六.克隆GitHub仓库 1.创建仓库目录,目录位置没有要求,比如D:\learngit. 2.配置ssh(如果不配置会每次都输入用户名和密码) 使用TortoiseGit生成ssh-key:开始菜单找到“”-->“PuTTYgen” 生成Key:并保存私钥为.ppk的私钥文件 注意:在生成过程中要不停摇晃鼠标增加随机性 在GitHub中添加公钥:登录GitHub,在右上角菜单中找到"Settings",在左面的导航里找到“SSH keys”,找到“Add SSH key”,将刚

DigitalOcean上SSH Key的创建(附DigitalOcean邀请)

DigitalOcean是一家云主机商家,最低配置512M内存,20G的SSD,每月只有5刀.半个月前刚刚在这上面买了一个VPS,创建Droplet的时候看见创建SSH Key的时候就有点懵,不知道这是做什么的,后来上网找到了解决方案,本文附上解决方法,当然主要目的是推荐一下DigitalOcean,附上我的邀请,点击www.digitalocean.com/?refcode=0cebdb63d25a注册,可以获得10刀,DigitalOcean最低配置每月5刀,所以相当于可以免费用两个月,选新

(诊断)为GitHub添加SSH key时出现“Could not open a connection to your authentication agent”错误的应对方案(转)

在为windows 环境下的github账户添加SSH key时,需要在Git Bash执行如下命令: 第一步:检查已有的SSH keys $ ls -al ~/.ssh 第二步:生成新的SSH key $ ssh-keygen -t rsa -C "[email protected]" # Creates a new ssh key, using the provided email as a label # Generating public/private rsa key pai

github添加SSH Key

1.背景介绍 缘由:在github上下载goagent时出现错误. 在终端使用命令:git clone [email protected]:phuslu/goagent.git 会报权限错误如下: Cloning into 'goagent'... The authenticity of host 'github.com (192.30.252.128)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:6

Mac Android studio提交本地项目到Github 已经配置 SSH KEY

注册账号 https://github.com 在本地配置ssh key秘钥 配置好之后这里需要它 开始本地配置ssh key,首先查看本地电脑是否有配置过ssh,进入终端 敲入$ defaults write com.apple.finder AppleShowAllFiles -bool true ( 显示隐藏文件(需要重新运行Finder),因为.ssh是隐藏文件). 在桌面菜单在查看是否有这个文件 .ssh 的隐藏文件,有的话个人建议删除. 现在开始在本地配置ssh key mkdir

github入门:设置添加ssh key&lt;转&gt;

转自:http://blog.csdn.net/binyao02123202/article/details/20130891 很多朋友在用github管理项目的时候,都是直接使用https url克隆到本地,当然也有有些人使用 SSH url 克隆到本地.然而,为什么绝大多数人会使用https url克隆呢? 这是因为,使用https url克隆对初学者来说会比较方便,复制https url 然后到 git Bash 里面直接用clone命令克隆到本地就好了.而使用 SSH url 克隆却需要