Git 配置 ssh
GitSSH
生成 ssh 密钥对
ssh-keygen -t rsa -C "user@example.com"生成的文件默认为 ~/.ssh/id_rsa 和 ~/.ssh/id_rsa.pub
配置
在终端输入 cat ~/.ssh/id_rsa.pub, 将公钥粘贴到目标平台的对应设置中.
如果使用了自定义的文件名称, 可能需要将配置加入到 ~/.ssh/config 中, 否则某些ssh工具无法找到对应的密钥.
config 文件基础语法如下
Host 别名
HostName 真实服务器地址
User 用户名
Port SSH端口号(默认22)
IdentityFile 私钥文件路径常见的GitHub配置如下
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/private_key_file_for_github测试
在终端输入 ssh -T git@github.com, 能看到输出如下
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.