CentOS 7之OpenSSH如何自动加载id_ed25519私钥认证
OpenSSH时默认私钥名字:
~/.ssh/id_rsa
~/.ssh/id_ecdsa
~/.ssh/id_ecdsa_sk
~/.ssh/id_ed25519
~/.ssh/id_ed25519_sk
~/.ssh/id_dsa
ed25519 是 目前 SSH 推荐算法:
特点:
| 算法 | 安全 | 速度 | key长度 |
|---|---|---|---|
| RSA | 中 | 慢 | 2048+ |
| ECDSA | 中 | 快 | 256 |
| ED25519 | 高 | 最快 | 256 |
所以现代系统基本默认:
ssh-keygen -t ed25519
比 RSA 更安全、更快。
1.验证SSH实际使用的key
1 | ssh -vT git@gitee.com |
你会看到类似:
debug1: Offering public key: /root/.ssh/id_ed25519
debug1: Offering public key: /root/.ssh/id_rsa
谁被接受:
debug1: Server accepts key: /root/.ssh/id_ed25519
2.强制指定key
做 Git / Gitee / GitHub 多 key 管理时,一定写 config。
~/.ssh/config
Host gitee.com
HostName gitee.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
关键参数:
IdentitiesOnly yes
作用:
只使用指定 key
不要尝试其他 key
否则 ssh 会乱试一堆 key。
3.多 Git 平台私钥认证
~/.ssh/config
Host gitee
HostName gitee.com
User git
IdentityFile ~/.ssh/id_ed25519
Host github
HostName github.com
User git
IdentityFile ~/.ssh/github_ed25519
使用:
git clone git@gitee:xxx/xxx.git
git clone git@github:xxx/xxx.git
4.指定key认证
命令:
ssh -i ~/.ssh/id_ed25519 git@gitee.com