GitHub配置SSH密钥

使用命令行生成SSH密钥对

ssh-key -t rsa # 根据提示一步步完成,选择是否配置密码。

操作完成后会在~/.ssh/目录下生成id_rsa id_rsa.pub两个文件 登录[[GitHub]],通过右上角的个人图像展开后的菜单选择settings,切换到“SSH and GPG keys”,添加一个SSH key,将id_rsa.pub的内容复制到文本框中保存即可. 在终端测试

ssh -T [email protected]

拉取代码仓库时使用SSH 地址格式类似于[email protected]:username/repo.git 如果要在其它电脑上使用密钥,将~/.ssh/目录下的id_rsa复制到该电脑相同目录即可。


多个SSH key

编辑~/.ssh/config

Host 172.25.0.52
  HostName 172.25.0.52
  User root

Host 172.23.0.52
  HostName 172.23.0.52
  User root

Host 172.23.210.33
  HostName 172.23.210.33
  User root

Host 172.23.210.22
  HostName 172.23.210.22
  IdentityFile C:\Users\Administrator\.ssh\test-01-id_rsa
  User root
Host 172.23.210.33
  HostName 172.23.210.33
  IdentityFile C:\Users\Administrator\.ssh\test-debian11-id_rsa
  User root
Host git.whkht.com
  HostName git.whkht.com
  IdentityFile C:\Users\Administrator\.ssh\liqiao_id_rsa.rsa
  User root

最后更新于