-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathg00_git_ssh-keygen.txt
More file actions
90 lines (62 loc) · 2.61 KB
/
g00_git_ssh-keygen.txt
File metadata and controls
90 lines (62 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
How to Set up SSH to work with GitHub
# --------------------------------------------------------------
Note - in 2021 GitHub switched their authentication rules.
Now you should use SSH.
You can add SSH key to your account or to a specific repository
(may be to a repo which is not yours, but you have access).
# --------------------------------------------------------------
Here how to add to your account
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
The link above provide instructions for Mac, Windows, and Linux.
They have some minor differences.
On Mac and Linux you use terminal.
On Windows you use Git Bash terminal.
Below is how to do it on a Mac:
ssh-keygen -t ed25519 -C "your_email@example.com"
/Users/you/.ssh/github_myname/id_ed25519_github
# Start the ssh-agent in the background
# and set env vars SSH_AUTH_SOCK, SSH_AGENT_PID to point to it
eval "$(ssh-agent -s)"
# add your key to the agent
ssh-add ~/.ssh/github_myname/id_ed25519_github
create/edit file ~/.ssh/config
Host *
AddKeysToAgent yes
Host github.com
User myuser
HostName github.com
IdentityFile ~/.ssh/github_myname/id_ed25519_github
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519_github
# -------------------------------------
# Then copy/paste public key into Github website:
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
# -------------------------------------
# Then switch the remote locally:
cd your_local_repo_dir
git remote set-url origin git@github.com:YouUser/YouRepo.git
git remote -v
origin git@github.com:YouUser/YouRepo.git (fetch)
origin git@github.com:YouUser/YouRepo.git (push)
# -------------------------------------
Note: to add a new key to a company's private repo,
follow instructions here:
https://cloud.redhat.com/blog/private-git-repositories-part-2a-repository-ssh-keys
Basically you need to generate the key pair
ssh-keygen -t ed25519 -C "first.last@gmail.com"
For example, you created these two keys:
$HOME/.ssh/github_myproject/github_id_ed25519
$HOME/.ssh/github_myproject/github_id_ed25519.pub
Then you update the .ssh/config file:
Host github.com
User githubuser
HostName github.com
IdentityFile /home/azureuser/.ssh/github_myproject/github_id_ed25519
IdentitiesOnly yes
Host *
AddKeysToAgent yes
Then login in github, go to the repo, click on settings (gear),
then on the left click on "Deploy keys",
and the on right-top click on "Add deploy key"
then follow instructions to paste the public key.
# -------------------------------------