美文网首页
Mac 如何生成SSH key

Mac 如何生成SSH key

作者: jsone | 来源:发表于2019-12-06 18:28 被阅读0次

一、SSH key简介

SSH key即SSH公钥,因为许多Git服务器都是支持使用SSH协议来访问 ,因此要通过SSH 协议来访问Git仓库需要向 Git 服务器提供 SSH 公钥

如果Git仓库未添加本地生成的SSH Key就会导致clone失败

$ git clone <git远程仓库地址>
Cloning into '项目名称'...
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

二、生成SSH key的步骤

  • 查看是否已经生成SSH Key
  • 生成新的SSH Key
  • 复制SSH Key添加到Git服务器
  1. 查看是否已经生成SSH Key
$ ls -al ~/.ssh
total 24
drwx------   5 <用户名>  staff   160 11  1  2018 .
drwxr-xr-x  54 <用户名>  staff  1728 12  6 13:36 ..
-rw-------   1 <用户名>  staff  1679 10 29  2018 id_rsa
-rw-r--r--@  1 <用户名>  staff   397 10 29  2018 id_rsa.pub
-rw-r--r--   1 <用户名>  staff   357  5 27  2019 known_hosts

查看SSH Key

$ cat /Users/<用户名>/.ssh/id_rsa.pub
ssh-rsa XXXXXXXXXXXX  <邮箱地址>
  1. 生成新的SSH Key
$ ssh-keygen -t rsa -C "<邮箱地址>"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/<用户名>/.ssh/id_rsa):
/Users/<用户名>/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/<用户名>/.ssh/id_rsa.
Your public key has been saved in /Users/<用户名>/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXX <邮箱地址>
The key's randomart image is:
+---[XXX XXX]----+
|      ..+*XxX .. |
|       .XX^ +..o|
|        ..% * oo+|
|       . + + +..=|
|        S * E. oo|
|         +    + .|
|          .  . . |
|                 |
|                 |
+----[XXXXXX]-----+
  1. 复制SSH Key添加到Git服务器

$ pbcopy < ~/.ssh/id_rsa.pub

到Git服务器添加SSH Key,重新clone项目成功

$ git clone  <git远程仓库地址>
Cloning into 'XXXXX'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

注意:
如果提示: Are you sure you want to continue connecting (yes/no)?
直接输入yes回车

$ ssh -T git@e.coding.net
The authenticity of host 'e.coding.net (111.123.70.251)' can't be established.
RSA key fingerprint is SHA156:jok3FH7q5LJ6qxX7iPNehBgXXXXw001ErE77S0Dn+Vg/Ik.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'e.coding.net,111.123.70.251' (RSA) to the list of known hosts.
Coding 提示: Hello 黄小明, You've connected to Coding.net via SSH. This is a personal key.
黄小明,你好,你已经通过 SSH 协议认证 Coding.net 服务,这是一个个人公钥

参考文章:
git 如何解决The authenticity of host 'git.coding.net (123.59.86.7)' can't be established问题

相关文章

  • Mac下如何生成SSH Key-使用GitLab

    原文Mac下如何生成SSH Key-使用GitLabMacbook使用Gitlab配置SSH Key 步骤1.检查...

  • ssh key 生成

    mac ssh key 生成 检查是否存在ls -al ~/.ssh 生成 ssh keya, ssh-keyg...

  • 利用 SSH 完成 Git 与 GitHub 的绑定

    git bush 下生成 SSH key Linux 系统:~/.ssh Mac 系统:~/.ssh Window...

  • mac 生成 ssh key

    一、检查当前mac是否已存在ssh key 输入以下命令:ls -al ~/.ssh 二、命令生成 ssh key...

  • Mac 如何生成SSH key

    一、SSH key简介 SSH key即SSH公钥,因为许多Git服务器都是支持使用SSH协议来访问 ,因此要通过...

  • MAC本地生成SSH KEY的方法

    MAC本地生成SSH KEY的方法 标签(空格分隔): MAC 打开终端查看是否已经存在SSH密钥 如果没有密钥则...

  • SSH Key的创建与查看

    查看本地是否存在SSH Key 生成新的SSH Key 生成并添加SSH Key 查看SSH Ket

  • MAC 生成SSH Key

    1,创建公钥,打开终端输入命令行 之后会让你输入保存路径,密码之类的 直接一路Enter,如下图,会自动给个默认...

  • Mac 生成SSH key

    git教程中提到

  • Mac 生成SSH Key

    1.检查是否已经存在SSH Key 输入终端命令:ls -al ~/.ssh (1)情况一:终端出现文件id_r...

网友评论

      本文标题:Mac 如何生成SSH key

      本文链接:https://www.haomeiwen.com/subject/tacegctx.html