• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

How to authenticate to Github with SSH

AnonyViet by AnonyViet
January 27, 2023
in Tips
0

Github offers two ways to authenticate your repository: over HTTPS with a password and over SSH with a private key. While both work well, if you want to switch Github authentication with SSH, you’ll need to configure your repository to use the new credentials.

Join the channel Telegram of the AnonyViet 👉 Link 👈

How to authenticate to Github with SSH

Configure Github Authentication with SSH

Github defaults to HTTPS authentication, using the password for your Github account. Whenever you clone a repo, you will have to manually select “SSH” as the option for URL cloning.

How to authenticate to Github with SSH 5

While SSH is generally best for authenticating connections to Linux servers, Github recommends HTTPS because it’s easier to use and less confusing. However, this is pretty bad for automation, isn’t technically as secure as an RSA key, and can be annoying having to type the password every time, even with credential caching.

Switching is pretty straightforward — you’ll need to generate a new SSH key if you don’t already have one, add it to your account, then swap your local repo to the new endpoint if you’ve already cloned.

First, check if you already have an SSH key. Your default key is usually stored here on Linux/macOS:

cat ~/.ssh/id_rsa.pub

On Windows, it depends on the program you are using. The key is sometimes stored in %HOMEDRIVE%%HOMEPATH%\.ssh\, but may be different based on how you are using Git. In most cases, I recommend using Windows Subsystem For Linux (WSL) acts like a virtual machine and stores the key in the Linux environment.

If you don’t have one, you can create one using ssh-keygen:

ssh-keygen -t rsa -f ~/.ssh/id_rsa

Once you have the key, go to Github settings under “SSH and GPG Keys” and paste the contents of id_rsa.pub into a new key.

How to authenticate to Github with SSH 6

Once done, you will be authenticated, as long as Git is set up to use this key.

Switch HTTPS Repo to SSH Authentication

If you clone from Github using HTTPS, your repository will be linked to Github using that remote URL. To work around this issue, you’ll need to remove the HTTPS remote, commonly called origin, and re-add it with the appropriate git@github URI for SSH usage.

git remote rm origin
git remote add origin [email protected]:user/repo.git

Then push origin as usual:

git fetch origin
git push --set-upstream origin/master

If you are cloning a new repo, you just need to make sure it is set to “SSH” in the future and that the URI is configured as [email protected].

How to authenticate to Github with SSH 7

Use a different SSH Key

However, if you have a lot of SSH keys to use, things can get complicated, which is why Github recommends passwords for newbies. Let’s say you clone the repo on your PC, but then want to work from your Laptop. You have to add a new key to your Github account or transfer the key to your Laptop.

If possible, you should add a new key. Github supports multiple keys for a number of reasons, and you can name them to sort the keys. However, sometimes, you will only have one key and need to fix everything on the client side.

If you just want to use the same key, you can transfer id_rsa and id_rsa.pub to the new machine. However, if that machine already has its own SSH key, you’ll need to use multiple keys.

You can do that by editing SSH’s server configuration file:

nano ~/.ssh/config

Add two blocks with different names. In this case, it is setting up different keys for personal and corporate accounts.

Host personal
  Hostname github.com
  IdentityFile ~/.ssh/githubpersonal
  IdentitiesOnly yes

Host work
  Hostname github.com
  IdentityFile ~/.ssh/githubwork
  IdentitiesOnly yes

You will need two keys named githubpersonal.pub and githubwork.pub or whatever name you choose to give them. Finally, you’ll need to remove the remote and re-add it, specifying the name of the block in the server config file (which may not match the key name):

git remote rm origin
git remote add origin git@personal:username/repository.git

In this command, “personal” will replace the hostname, github.com, in the URL. The reason this is necessary is that SSH’s configuration defaults to choosing the key based on the hostname, in both the personal and work blocks it’s just github.com. You have to specify it manually so that Git can pick the right one.

The article achieved: 5/5 – (100 votes)

Tags: authenticateGithubSSH
Previous Post

Các Website giúp cải thiện kỹ năng Hack bằng bài tâp cơ bản

Next Post

How to create a Windows 7GB RAM VPS without VISA from Cloud Shell Azure

AnonyViet

AnonyViet

Related Posts

How to see your email account creation date
Tips

How to see your email account creation date

November 11, 2025
Microsoft’s ranking of the 10 best Windows versions
Tips

Microsoft’s ranking of the 10 best Windows versions

November 11, 2025
Recover deleted data on Windows 10 with Windows File Recovery
Tips

Recover deleted data on Windows 10 with Windows File Recovery

November 10, 2025
Tips

Why hasn’t your computer been updated to Windows 10 2004?

November 9, 2025
3 OCR Tools Extract Text from Images without Retyping
Tips

3 OCR Tools Extract Text from Images without Retyping

November 8, 2025
Ways hackers use to hack your Facebook and how to fix it
Tips

Ways hackers use to hack your Facebook and how to fix it

November 7, 2025
Next Post
How to create a Windows 7GB RAM VPS without VISA from Cloud Shell Azure

How to create a Windows 7GB RAM VPS without VISA from Cloud Shell Azure

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

How to install Anh Hai’s Pho Shop on MacBook is super easy

How to install Anh Hai’s Pho Shop on MacBook is super easy

November 11, 2025
How to turn off ads on Yoosee app in just 1 minute

How to turn off ads on Yoosee app in just 1 minute

November 11, 2025
Windows 11 and MS Office 2021 lifetime license, genuine from  during Keysoff’s 11.11 sale

Windows 11 and MS Office 2021 lifetime license, genuine from $14 during Keysoff’s 11.11 sale

November 11, 2025
How to see your email account creation date

How to see your email account creation date

November 11, 2025
How to install Anh Hai’s Pho Shop on MacBook is super easy

How to install Anh Hai’s Pho Shop on MacBook is super easy

November 11, 2025
How to turn off ads on Yoosee app in just 1 minute

How to turn off ads on Yoosee app in just 1 minute

November 11, 2025
Windows 11 and MS Office 2021 lifetime license, genuine from  during Keysoff’s 11.11 sale

Windows 11 and MS Office 2021 lifetime license, genuine from $14 during Keysoff’s 11.11 sale

November 11, 2025
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

How to install Anh Hai’s Pho Shop on MacBook is super easy

How to install Anh Hai’s Pho Shop on MacBook is super easy

November 11, 2025
How to turn off ads on Yoosee app in just 1 minute

How to turn off ads on Yoosee app in just 1 minute

November 11, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

new88 trang chủ shbet trang chủ f168 trang chủ qq88 nhà cái 78win

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

new88 trang chủ shbet trang chủ f168 trang chủ qq88 nhà cái 78win

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply