Blame
|
1 | # SSH |
||||||
| 2 | ||||||||
| 3 | ## 创建 SSH 密钥对 |
|||||||
| 4 | ||||||||
| 5 | ```sh |
|||||||
| 6 | ssh-keygen -t ed25519 -C "用户名@备注信息" |
|||||||
| 7 | ``` |
|||||||
| 8 | ||||||||
| 9 | > 引号中内容为备注信息,可以任意填写 |
|||||||
| 10 | > |
|||||||
| 11 | > 默认保存路径 ~/.ssh/ , 私钥: ~/.ssh/id_ed25519 , 公钥: ~/.ssh/id_ed25519.pub |
|||||||
| 12 | ||||||||
| 13 | <details> |
|||||||
| 14 | <summary> |
|||||||
| 15 | 在不支持ed25519 算法的老旧系统中生成密钥 |
|||||||
| 16 | </summary> |
|||||||
| 17 | ||||||||
| 18 | ```sh |
|||||||
| 19 | ssh-keygen -t rsa -b 4096 -C "用户名@备注信息" |
|||||||
| 20 | ``` |
|||||||
| 21 | </details> |
|||||||
| 22 | ||||||||
| 23 | ## SSH 配置文件 |
|||||||
| 24 | ||||||||
| 25 | 连接保活,每60秒发送一个 keep-alive 包 |
|||||||
| 26 | ||||||||
| 27 | > cat ~/.ssh/config |
|||||||
| 28 | ||||||||
| 29 | ```ini |
|||||||
| 30 | ServerAliveInterval 60 |
|||||||
| 31 | ||||||||
| 32 | # 开启ssh-agent转发 |
|||||||
| 33 | Host * |
|||||||
| 34 | ForwardAgent yes |
|||||||
| 35 | ||||||||
| 36 | # 针对特定主机开启 ssh-agent 转发 |
|||||||
| 37 | Host github |
|||||||
| 38 | HostName github.com |
|||||||
| 39 | IdentityFile ~/.ssh/id_ed25519 |
|||||||
| 40 | User git |
|||||||
| 41 | ForwardAgent yes |
|||||||
| 42 | ``` |
|||||||
|
43 | |||||||
| 44 | ||||||||
| 45 | ```sh |
|||||||
| 46 | eval `ssh-agent -s` |
|||||||
| 47 | ssh-add |
|||||||
| 48 | ``` |
|||||||