查看版本

$ ssh -V
OpenSSH_7.6p1, OpenSSL 1.0.2n 7 Dec 2017

http://superuser.com/questions/232373/how-to-tell-git-which-private-key-to-use

In ~/.ssh/config, add:

host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa_github
User git

Now you can do git clone git@github.com:username/repo.git.

NOTE: Verify that the permissions on IdentityFile are 400.SSH will reject, in a not clearly explicit manner, SSH keys that are too readable. It will just look like a credential rejection. The solution, in this case, is:

chmod 400 ~/.ssh/id_rsa_github

https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html

Step 1. Ensure you have an SSH client installed

SSH should be included with the version of Git you installed. To make sure, do the following to verify your installation:

  1. From the Git Bash window, enter the following command to verify that SSH client is available:

    $ ssh -v 
    OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
    usage: ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
    [-D [bind_address:]port] [-e escape_char] [-F configfile]
    [-i identity_file] [-L [bind_address:]port:host:hostport]
    [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
    [-R [bind_address:]port:host:hostport] [-S ctl_path]
    [-w local_tun[:remote_tun]] [user@]hostname [command]

    If you have ssh installed, the terminal returns version information.

    If you don't have ssh installed, install it now with your package manager.

  2. List the contents of your ~/.ssh directory.
    If you have not used SSH on Git Bash yet, you might see something like this:

    $ ls -a ~/.ssh 
    ls: /c/Users/emmap1/.ssh: No such file or directory

    If you have a default identity already, you'll see two id_* files:

    $ ls -a ~/.ssh 
    .    ..    id_rsa    id_rsa.pub  known_hosts

    In this case, the default identity uses RSA encryption (id_rsa.pub). If you want to use an existing default identity for your Bitbucket account, skip the next section and go to create a config file.

Step 2. Set up your default identity

By default, the system adds keys for all identities to the /Users/<yourname>/.ssh directory. The following procedure creates a default identity.

  1. Open a terminal in your local system.
  2. Enter ssh-keygen at the command line. 
    The command prompts you for a file to save the key in:

    $ ssh-keygen 
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/emmap1/.ssh/id_rsa):
  3. Press enter to accept the default key and path, /c/Users/<yourname>/.ssh/id_rsa, or you can create a key with another name.
    To create a key with a name other than the default, specify the full path to the key. For example, to create a key called my-new-ssh-key, you would enter a path like this at the prompt:

    $ ssh-keygen 
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Documents and Settings/emmap1/.ssh/id_rsa): /c/Users/emmap1/My Documents/keys/my-new-ssh-key
  4. Enter and renter a passphrase when prompted.
    Unless you need a key for a process such as script, you should always provide a passphrase. 
    The command creates your default identity with its public and private keys. The whole interaction looks similar to the following:

    $ ssh-keygen 
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/emmap1/.ssh/id_rsa):
    Created directory '/c/Users/emmap1/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /c/Users/emmap1/.ssh/id_rsa.
    Your public key has been saved in /c/Users/emmap1/.ssh/id_rsa.pub.
    The key fingerprint is: e7:94:d1:a3:02:ee:38:6e:a4:5e:26:a3:a9:f4:95:d4 emmap1@EMMA-PC
  5. List the contents of ~/.ssh to view the key files.
    You should see something like the following:

    $ ls ~/.ssh 
    id_rsa id_rsa.pub

    The command created two files, one for the public key (for example id_rsa.pub) and one for the private key (for example, id_rsa).

Step 3. Create a SSH config file

  1. Using your favorite text editor, create a new file (at ~/.ssh/config) or edit the file if it already exists.

  2. Add an entry to the configuration file using the following format:

     
     
     
     
     
    1
    Host bitbucket.org
    2
     IdentityFile ~/.ssh/<privatekeyfile>
     
     

    The second line is indented. That indentation (a single space) is important, so make sure you include it. The second line is the location of your private key file.  If you are following along with these instructions, enter id_rsa for<privatekeyfile>.

    When you are done editing, your configuration looks similar to the following:

     
     
     
     
     
    1
    Host bitbucket.org
    2
     IdentityFile ~/.ssh/id_rsa
     
     
  3. Save and close the file.
  4. Restart the GitBash terminal.

git使用ssh协议,生成公钥和私钥,并指定私钥的更多相关文章

  1. github git clone ssh协议 clone超慢解决方案,提高Github Clone速度

    即使进行了fq吧但是git clone ssh协议就是慢 2kb/s你能忍,坚决不能忍. github git clone ssh协议 clone超慢解决方案 151.101.72.249 globa ...

  2. 使用idea操作git(ssh协议)

    问题 我们发现,使用IDEA上的git功能,当使用ssh协议出现了可以commit但无法push和pull的问题,经过测试发现原因是Could not read from remsitory.直接翻译 ...

  3. Git和SSH协议

    SSH(安全外壳协议)为Secure Shell的缩写,由IETF的网络工作小组(Network Working Group)所制定:SSH为建立在应用层和传输层基础上的安全协议.SSH是目前较可靠, ...

  4. Git for Windows之使用SSH协议开通公钥免密登陆功能

    1.删除Https的通信方式,建立SSH的通信方式 (1).查看当前的通信方式 当前是使用Https的方式与远程仓库进行通信 (2).删除HTTPS的通信方式 ok,HTTPS通信方式已删除 (3). ...

  5. Git 中 SSH key 生成步骤

    由于本地Git仓库和GitHub仓库之间的传输是通过SSH加密的,所以必须要让github仓库认证你SSH key,在此之前,必须要生成SSH key. 第1步:创建SSH Key.在windows下 ...

  6. git生成公钥public key并添加SSH key。git乌龟gerrit下推送git【server sent :publickey】

    一.key 码云链接:http://git.mydoc.io/?t=180845#text_180845 博客链接: 方式一:https://blog.csdn.net/xb12369/article ...

  7. Git : SSH 协议服务器

    SSH 协议用于为 Git 提供远程读写操作,是远程写操作的标准服务. SSH协议语法格式 对于拥有 shell 登录权限的用户账号,可以用下面的语法访问 Git 版本库: 语法 1 : ssh:// ...

  8. 15.Git四种协议-本地协议(local)、HTTP协议、SSH协议、Git协议

    1.本地协议(loacl) 最基本的协议,其远程仓库其实就是硬盘内部的一个目录(例如D:\\project).常见于团队内的人对一个共享的文件系统(例如NFS)具有访问权限,或者多人共用一台电脑的情况 ...

  9. centos7.5下生成公钥,实现ssh免密钥登陆

    配置SSH无密码登录需要4步准备工作生成公钥和私钥导入公钥到认证文件,更改权限测试1. 准备工作确认本机sshd的配置文件(需要root权限) # vi /etc/ssh/sshd_config 1找 ...

随机推荐

  1. Somebody That I Used to Know

    一.查看歌词 http://baike.baidu.com/view/7925491.htm 二.考量歌词 1.我告诉自己你就是我的挚爱 但你的陪伴却让我倍感孤单 但那就是爱 让我刻骨铭心难以忘怀 既 ...

  2. [Js/Jquery]天气接口简单使用

    写在前面 今天在群里有朋友使用一个天气api,觉得挺实用的,就记录一下.省的以后再花费功夫去找. 地址:http://www.k780.com/api,在这个网站提供了实用的几种接口,比如查询ip,天 ...

  3. ASP.NET页面优化性能提升方法记录

    今天与大家分享:一种优化页面执行速度的方法.采用这个方法,可以使用页面的执行速度获得[8倍]的提升效果. 为了让您对优化的效果有个直观的了解,我准备了下面的测试结果截图: 测试环境:1. Window ...

  4. ASP.NET中的事件处理

    一.ASP.NET中的事件主要支持3个主要的事件组:1.包含在asp.net生成页面时自动生成,我们使用这些事件建立页面(如page_load等)2.包含了用户与页面交互时发生的所有事件(这种最强大) ...

  5. 定时器 corn 表达式

    一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素.按顺序依次为1.秒(0~59)2.分钟(0~59)3.小时(0~23)4.天(月)(0~31,但是你需要考虑你月的天数)5.月(0~11 ...

  6. 初识layer 快速入门

    http://layer.layui.com/hello.html 如果,你初识layer,你对她不知所措,你甚至不知如何绑定事件… 那或许你应该用秒做单位,去认识她. 开始了解 第一步:部署 下载l ...

  7. 小圣求职记B:总集篇

    1. 搜狐sohu 搜狐在正式招聘前邀请了部分应聘者到武汉研发中心开座谈会(因此简历尽量早投,机会多些),有研发的也有产品的,40人左右,座谈会期间介绍了搜狐汽车.北京研发中心.武汉研发中心和搜狐媒体 ...

  8. HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)

    题目 线段树 简单题意: 区间(单点?)更新,区间求和  更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...

  9. 转载:PHP,MySQL的安装与配置

    本文转自:http://www.cnblogs.com/janas/archive/2012/08/27/2659240.html 一.安装配置PHP 1.下载Php的版本zip包之后,解压缩到指定目 ...

  10. POJ 1961

    #include<iostream> #include<stdio.h> #define MAXN 1000001 using namespace std; char c[MA ...