# mutli_ssh_config **Repository Path**: jiodg45/mutli_ssh_test ## Basic Information - **Project Name**: mutli_ssh_config - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-12-14 - **Last Updated**: 2021-09-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## 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`. 2. 生成ssh密钥并在同目录下面 ```shell 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" ``` 3. 以其中一个ssh密钥生成记录来看,终端会为我们生成如下文件,下面log记录了 - `public key`和`private key`的生成目录 - `fingerprint`指纹签名 - RSA密钥长度位数为2048位.也可以通过`-b`参数指定,为1024的倍数。 ```terminal 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]-----+ ``` 2. 然后进入到`./ssh/`目录可以看到我们刚才创建的2个密钥: ```tree ├── id_rsa.github ├── id_rsa.github.pub ├── id_rsa.gitlab ├── id_rsa.gitlab.pub ``` 3. 在此目录下心间config文件,内容如下: ```tree #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 ``` 4. 添加私钥匙 ``` ssh-add ~/.ssh/id_rsa.github ``` 5. 将对应的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的链接信息。 6. 然后就可以愉快的获取对应仓库的代码了。 ``` 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](https://blog.gitee.com) 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) 4. The most valuable open source project [GVP](https://gitee.com/gvp) 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)