SSH key提供了一种与GitHub通信的方式,通过这种方式,能够在不输入密码的情况下,将GitHub作为自己的remote端服务器,进行版本控制

步骤

  • 检查SSH keys是否存在
  • 生成新的ssh key
  • 将ssh key添加到GitHub中

如何生成SSH KEY

1. 检查SSH keys是否存在

输入下面的命令,如果有文件id_rsa.pub 或 id_dsa.pub,则直接进入步骤3将SSH key添加到GitHub中,否则进入第二步生成SSH key

ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

2. 生成新的ssh key

第一步:生成public/private rsa key pair
在命令行中输入ssh-keygen -t rsa -C "your_email@example.com"

默认会在相应路径下(/your_home_path)生成id_rsaid_rsa.pub两个文件,如下面代码所示

ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_rsa):

第二步:输入passphrase(本步骤可以跳过)

设置passphrase后,进行版本控制时,每次与GitHub通信都会要求输入passphrase,以避免某些“失误”

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

sample result:

Your identification has been saved in /your_home_path/.ssh/id_rsa.
Your public key has been saved in /your_home_path/.ssh/id_rsa.pub.
The key fingerprint is:
#01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

第三步:将新生成的key添加到ssh-agent中:

# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
ssh-add ~/.ssh/id_rsa

3. 将ssh key添加到GitHub中

用自己喜欢的文本编辑器打开id_rsa.pub文件,里面的信息即为SSH key,将这些信息复制到GitHub的Add SSH key页面即可

不同的操作系统,均有一些命令,直接将SSH key从文件拷贝到粘贴板中,如下:

mac

pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

windows

clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

linux

sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`) xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

 

如何生成SSH key的更多相关文章

  1. Git 生成SSH Key

    背景:服务器是LINUX系统(centos7),使用GitLab管理git代码库.各个客户端通过sourcetree 工具,采用SSH获取.提交代码.使用SSH的方式需要公钥和私钥.下面介绍秘钥的生成 ...

  2. Git - 生成 ssh key for Mac

    终端: cd ~/ .ssh 生成 SSH KEY ssh-keygen -t rsa -C 你的油箱 前往以下目录找到生成好的 SSH KEY /Users/wzz/.ssh/id_rsa.pub

  3. win7生成ssh key配置到gitlab

    测试服务上使用ip访问gitlab,比如http://192.168.0.2/,创建用户并登陆后创建一个项目,比如git@gitlab.demo.com:demo/helloworld.git 如果想 ...

  4. Git - 生成ssh key步骤以及如何clone所有的远程分支

    https://www.cnblogs.com/gongyuhonglou/p/6922721.html 2. 生成ssh key $ ssh-keygen -t rsa -C “邮箱”按3个回车,密 ...

  5. Win环境 Android Studio使用Git 教程 ( 生成SSH key )

    Github和码云都提供SSH协议,即用户可以用公钥认证方式连接到码云的SSH服务器.这就需要生成并部署SSH Key.下面就是我生成SSH Key的步骤,希望有所帮助: Git生成SSH key 在 ...

  6. git之生成SSH key

    git之生成SSH key SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定.利用 SSH 协议可以有效防止远程管理过程中的信 ...

  7. git生成ssh key和多账号支持

    git配置ssh 1.首先设置git的全局user name和email $ git config --global user.name "ygtzz"$ git config - ...

  8. git生成ssh key及本地解决多个ssh key的问题

    git生成ssh key及本地解决多个ssh key的问题 ssh是一种网络协议,用于计算机之间的加密登录.ssh原理及应用可参考: SSH原理与运用(一):远程登录 生成ssh key步骤 这里以配 ...

  9. 如何给 GitHub 添加 SSH key, 如何生成 SSH key 详细图文教程!

    如何给 GitHub 添加  SSH key, 如何生成  SSH key 详细图文教程! 一. 生成  SSH key https://ide.c9.io/xgqfrms/ 创建一个空项目:(或使用 ...

随机推荐

  1. CodeForces 732B Cormen — The Best Friend Of a Man

    B. Cormen - The Best Friend Of a Man time limit per test 1 second memory limit per test 256 megabyte ...

  2. 后端UI框架

    BootStrap EasyUI DWZ ExtJS

  3. python and 我爱自然语言处理

    曾经因为NLTK的 缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开发语言是C/C++,但平时的很多文本数据处理任务都交给了Python.离 开腾讯创业后,第一个作品课程图谱也 ...

  4. golang: multiple http.writeHeader calls

    背景: golang的http服务,读取文件,提供给client下载时候. 出现 multiple http.writeHeader calls 错误. func DownloadFile(w htt ...

  5. django中实现微信消息推送

    -公众号(不能主动给用户发消息) -认证的公众号:需要营业执照,需要交钱,可以发多篇文章 -未认证的公众号:一天只能发一篇文章 -服务号(微信推送) -需要申请,需要认证 -可以主动给用户推送消息 - ...

  6. redis哨兵集群、docker入门

    redis-sentinel主从复制高可用 Redis-Sentinel Redis-Sentinel是redis官方推荐的高可用性解决方案,当用redis作master-slave的高可用时,如果m ...

  7. (0.1)windows下的mysql配置使用步骤

    目录 1.基于windows平台的mysql项目场景 2.mysql数据库运行环境准备 3.下载mysql 4.通过Installer方式(即msi方式)安装mysql 5.卸载mysql ————— ...

  8. SIP中的 session, dialog 及 transaction 的解释

    http://stackoverflow.com/questions/35133331/difference-between-session-dialog-and-transaction-in-sip ...

  9. Spark的集群管理器

    上篇文章谈到Driver节点和Executor节点,但是如果想要运行Driver节点和Executor节点,就不能不说spark的集群管理器.spark的集群管理器大致有三种,一种是自带的standa ...

  10. vim使用winmanager整合nerd tree和taglist

    winmanager插件安装 • 插件简介 winmanager is a plugin which implements a classical windows type IDE in Vim-6. ...