1 Star 0 Fork 0

逐风 / mutli_ssh_config

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

SSH

  1. 怎样使用ssh配置多个ssh密钥,首先打开终端,检查ssh-keygen是否有安装,Mac系统自带,然后查看其帮助命令。ssh help:
usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa]
[-N new_passphrase] [-C comment] [-f output_keyfile]
ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
ssh-keygen -i [-m key_format] [-f input_keyfile]
ssh-keygen -e [-m key_format] [-f input_keyfile]
ssh-keygen -y [-f input_keyfile]
ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
ssh-keygen -B [-f input_keyfile]
ssh-keygen -D pkcs11
ssh-keygen -F hostname [-f known_hosts_file] [-l]
ssh-keygen -H [-f known_hosts_file]
ssh-keygen -R hostname [-f known_hosts_file]
ssh-keygen -r hostname [-f input_keyfile] [-g]
ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines]
[-j start_line] [-K checkpt] [-W generator]
ssh-keygen -s ca_key -I certificate_identity [-h] [-U]
[-D pkcs11_provider] [-n principals] [-O option]
[-V validity_interval] [-z serial_number] file ...
ssh-keygen -L [-f input_keyfile]
ssh-keygen -A
ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]
file ...
ssh-keygen -Q -f krl_file file ...
  • 这里重点需要注意 -t指定ssh的密钥类型,一般选rsa(非对称加密)
  • -C对密钥加上自己的备注
  • -f指定known_hosts_file.
  1. 生成ssh密钥并在同目录下面
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "zhangkui305@163.com"
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitlab -C "zhangkui305@163.com"
  1. 以其中一个ssh密钥生成记录来看,终端会为我们生成如下文件,下面log记录了
  • public keyprivate key的生成目录
  • fingerprint指纹签名
  • RSA密钥长度位数为2048位.也可以通过-b参数指定,为1024的倍数。
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/longxiang/.ssh/id_rsa.github.
Your public key has been saved in /Users/longxiang/.ssh/id_rsa.github.pub.
The key fingerprint is:
SHA256:ocviE32+0q4aDMpT7BV+Lbog02K0Xm7WVBjj2IkhBrE zhangkui305@163.com
The key's randomart image is:
+---[RSA 2048]----+
|+.               |
| + . o           |
|E . *.= .        |
|  .o.=.o..       |
| ..o +ooS.       |
|o.=ooo+.o        |
|.O =*oo+         |
|o B+o+o o        |
| .o.o+.+o.       |
+----[SHA256]-----+
  1. 然后进入到./ssh/目录可以看到我们刚才创建的2个密钥:
├── id_rsa.github
├── id_rsa.github.pub
├── id_rsa.gitlab
├── id_rsa.gitlab.pub
  1. 在此目录下心间config文件,内容如下:
#github
Host github
Hostname github.com
user user@github.com
IdentityFile ~/.ssh/id_rsa.github
#gitlab
Host gitlab
Hostname gitlab.com
user user@gitlab.com
IdentityFile ~/.ssh/id_rsa.gitlab
#gitee 
Host gitee
Hostname gitee.com
user user@gitee.com
IdentityFile ~/.ssh/id_rsa.gitee
  1. 添加私钥匙
ssh-add ~/.ssh/id_rsa.github
  1. 将对应的pub密钥贴到你的git账号仓库的sshkeys中,激活ssh密钥
ssh -T git@gitee.com
The authenticity of host 'gitee.com (212.64.62.174)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,212.64.62.174' (ECDSA) to the list of known hosts.
Hi 逐风! You've successfully authenticated, but GITEE.COM does not provide shell access.
  • 同时.ssh目录下面也会生成一个known_hosts它记录远程domain的链接信息。
  1. 然后就可以愉快的获取对应仓库的代码了。
git clone git@gitee.com:jiodg45/mutli_ssh_test.git

Gitee Feature

  1. You can use Readme_XXX.md to support different languages, such as Readme_en.md, Readme_zh.md
  2. Gitee blog blog.gitee.com
  3. Explore open source project https://gitee.com/explore
  4. The most valuable open source project GVP
  5. The manual of Gitee https://gitee.com/help
  6. The most popular members https://gitee.com/gitee-stars/

空文件

简介

暂无描述 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/jiodg45/mutli_ssh_test.git
git@gitee.com:jiodg45/mutli_ssh_test.git
jiodg45
mutli_ssh_test
mutli_ssh_config
master

搜索帮助