美文网首页
Git SSH配置

Git SSH配置

作者: 木沐橙光 | 来源:发表于2023-05-16 11:46 被阅读0次

Git SSH配置

未配置过git账号 无 .ssh 文件夹

  • 查看是否存在 .ssh 文件夹 命令
cd ~/.ssh/
  • 创建 .ssh 文件夹 命令
# 这里设置目录为 C:\Users
mkdir ../.ssh/

配置全局

  • 查看全局配置
# 查询是否配置过 user.name 和 user.email
git config --global --list
  • 设置全局配置
# 设置全局用户名
git config --global user.name 用户名
# 设置全局邮箱
git config --global user.email 邮箱
  • 清除全局配置
# 清除全局用户名
git config --global --unset user.name 
# 清除全局邮箱
git config --global --unset user.email 

git多账号配置

  • 创建config文件
touch config
  • 创建新的SSH keys
# 直接回车 创建的是默认生成的 id_rsa和id_rsa.pub
ssh-keygen -t rsa -C 邮箱

注意:
如果需要自定义文件名
则需要在提示输入文件名的时候
Enter file in which to save the key (~/.ssh/id_rsa): id_rsa_new
id_rsa_new就是自定义的文件名

  • 添加到SSH agent中
ssh-add ~/.ssh/id_rsa_work   

注意:
如果报错提示 Could not open a connection to your authentication agent
解决方案:

ssh-agent bash
ssh-add ~/.ssh/你设置的文件名 (例如:id_rsa)
  • 配置到 config 文件中
# 这里我以coding为例 
Host git@e.coding.net
 HostName https://e.coding.net
 User git
 IdentityFile ~/.ssh/id_rsa_coding_private
  • 测试是否连接到coding
ssh -T git@e.coding.net

相关文章

网友评论

      本文标题:Git SSH配置

      本文链接:https://www.haomeiwen.com/subject/hdxbsdtx.html