macOS设置GitHub公钥命令行登录
- 本地生成 SSH 密钥和公钥
ssh-keygen -t ed25519 -C "email"
注意⚠️:
- 命名:~/.ssh/id_ed25519_other
- 密码:可以输入复杂的密码
- 本地将公钥复制到剪贴板:
pbcopy < ~/.ssh/id_ed25519_other.pub
-
配置 GitHub 的 SSH Key:打开 Github > Settings > SSH and GPG keys > SSH keys,点击 New SSH key,粘贴
-
设置
~/.ssh/config
文件:
Host github.com
IdentityFile ~/.ssh/id_ed25519_other
PreferredAuthentications publickey
AddKeysToAgent yes
UseKeychain yes
注意⚠️:
UseKeychain yes
可以保存在第 1 步的密码,这样每次进行 GitHub 上传时,就不需要每次输入密码 Enter passphrase for key。- 网上有很多教程,为了避免每次 GitHub 上传时输入公钥的密码,直接在第 1 步输入空密码,这样不安全,非常不可取。
- 打开终端,验证一下是否添加 SSH 成功:
ssh -T git@github.com
Hi name! You've successfully authenticated, but GitHub does not provide shell access.