赞
踩
$ ssh-keygen -t ed25519 -C "your_email@example.com"
不支持Ed25519的旧机器:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
$ ssh-add --apple-use-keychain ~/.ssh/id_ed25519
$ #--apple-use-keychain等同于废弃的-K
Host github.com #host别名,使用ssh时按此匹配配置
HostName github.com #真实主机地址(域名|IP)
AddKeysToAgent yes #使用ssh时自动添加私钥到ssh-agent(不启用的话需要按方式一手动添加)
UseKeychain yes #使用钥匙串填充密码(等同于--apple-use-keychain)
PreferredAuthentications publickey #使用公钥认证而不是账号密码
IdentityFile ~/.ssh/id_ed25519 #证书文件(私钥)
测试是否成功连接:
$ ssh -T git@github.com
$ #拷贝公钥
$ cat ~/.ssh/id_ed25519.pub |pbcopy
$ git config user.email "xxx@xxx.com"
$ git config user.name "xxname"
$ #或直接在仓库配置文件中修改,.git/config
# github账号 Host github.com HostName github.com User git AddKeysToAgent yes UseKeychain yes PreferredAuthentications publickey IdentityFile ~/.ssh/id_ed25519 # 其他github账号 Host xxx.github.com HostName github.com User git AddKeysToAgent yes UseKeychain yes PreferredAuthentications publickey IdentityFile ~/.ssh/id_ed25519_xxx # gitee账号 Host gitee.com HostName gitee.com User git AddKeysToAgent yes UseKeychain yes PreferredAuthentications publickey IdentityFile ~/.ssh/id_ed25519_gitee
确认各个配置是否能成功连接:
3. 修改本地仓空中远程URL的域名(☀️☀️☀️XXX.github.com☀️☀️☀️需同~/.ssh/config中的对应Host匹配)
$ git remote rm origin
$ git remote -v
$ git remote add origin git@XXX.github.com:xxx/xxx.git
可先执行:
$ ssh -T git@github.com # 触发(AddKeysToAgent)
或在.bash_profile中添加:
$ ssh-add ~/.ssh/id_ed25519 > /dev/null 2>&1
$ ssh-add ~/.ssh/id_ed25519_xxx > /dev/null 2>&1
$ ssh-add ~/.ssh/id_ed25519_yyy > /dev/null 2>&1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。