文章目录
  • .ssh目录
  • 生成新的ssh
  • 配置
  • 添加公钥到仓库
  • 验证


.ssh目录

windows下一般为:C:\Users\15237\.ssh ,其中“15237”为当前登录用户

生成新的ssh

.ssh目录下打开“Git Bash Here”(如果没有,先安装 Git 软件)

windows sshkeygen 多平台添加配置_git


执行命令:

ssh-keygen -t rsa -C "your_email_adress" -f id_rsa_github2 -C "Github2"
例如:
ssh-keygen -t rsa -C "huadongyuan@yongjia" -f codeup_hdy_id_rsa -C "CodeUpHdy"
  • 1.
  • 2.
  • 3.

“your_email_adress” 替换成你的邮箱账号, -f id_rsa_github2 文件名,可以自定义,默认为 id_rsa ,-C “Github2” 为描述信息

windows sshkeygen 多平台添加配置_ssh公钥_02


生成期间会要求输入两次密码,不用输入,直接回车。

配置

.ssh目录下找到 config 文件,如果没有,请创建一个(注意,无文件扩展后缀)
添加如下内容:

# 云效-hdy
Host hdy_codeup.aliyun.com
    HostName codeup.aliyun.com
    IdentityFile ~/.ssh/codeup_hdy_id_rsa
    PreferredAuthentications publickey
    IdentityAgent none
    IdentitiesOnly yes
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

注意:如果已经添加过其他企业的 云效/gitee/github 等 host 地址,那么 host 地址一定不要重复,否则不起作用,可以根据企业特征重新定义一个 Host 地址,配置 origin 时使用这个 Host 地址代替代码仓库中的域名地址即可。

添加公钥到仓库

windows sshkeygen 多平台添加配置_ssh config Host_03


找到刚刚生成的 codeup_hdy_id_rsa.pub 公钥文件并打开,复制文件中的内容到 云效-个人设置-SSH公钥 并添加;

windows sshkeygen 多平台添加配置_git_04


windows sshkeygen 多平台添加配置_git_05


windows sshkeygen 多平台添加配置_多平台id_rsa_06

验证

windows sshkeygen 多平台添加配置_windows_07


观察 git clone 命令可以知道,原来的域名为:git@codeup.aliyun.com:xxxxxxxxxxxx/xxxxxxxxxxxxxx.git,我们在使用时改为了:git@hdy_codeup.aliyun.com:xxxxxxxxxxxx/xxxxxxxxxxxxxx.git

只要思想不滑坡,办法总比困难多<.b>********************************