github SSH
(GITHUB官网)
Before-check
- 检查现有SSH密钥:
1 | $ ls -al ~/.ssh |
Check the directory listing to see if you already have a public SSH key. By default, the filenames of supported public keys for GitHub are one of the following.
- id_rsa.pub
- id_ecdsa.pub
- id_ed25519.pub
Generating a new SSH key
- 打开Git Bash;
- 生成SSH:
1 | ssh-keygen -t ed25519 -C "your_email@example.com" |
Adding your SSH key to the ssh-agent
- In a new admin elevated PowerShell window, ensure the ssh-agent is running. You can use the “Auto-launching the ssh-agent” instructions in “Working with SSH key passphrases“, or start it manually.
auto version:
You can run ssh-agent automatically when you open bash or Git shell. Copy the following lines and paste them into your ~/.profile or ~/.bashrc file in Git shell:
1 | env=~/.ssh/agent.env |
If your private key is not stored in one of the default locations (like ~/.ssh/id_rsa), you’ll need to tell your SSH authentication agent where to find it. To add your key to ssh-agent, type ssh-add ~/path/to/my_key
- In a terminal window without elevated permissions, add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
1 | ssh-add c:/Users/YOU/.ssh/id_ed25519 |
Adding a new SSH key to your GitHub account
Copy the SSH public key to your clipboard.
If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace.
1 | $ clip < ~/.ssh/id_ed25519.pub |
然后进github复制粘贴就行了