← Back to Git Course | Chapter 1: Introduction & Setup | Lesson 7 of 7

Git SSH Setup

SSH keys आपके computer और GitHub के बीच एक special secret handshake जैसी हैं। एक बार वे एक-दूसरे का handshake जान लें, आपको हर बार अपना password type करने की ज़रूरत नहीं।
Syntax
bash
ssh-keygen -t ed25519 -C "[email protected]"
cat ~/.ssh/id_ed25519.pub
ssh -T git@host_name
git clone git@host_name:user/repo.git

Git के साथ SSH क्यों इस्तेमाल करें

HTTPS remotes हर push पर आपका username और एक personal access token माँगते हैं जब तक आप credentials cache न करें, जबकि SSH आपकी machine पर stored एक key pair से authenticate करता है -- एक बार set up हो जाने पर, push और pull करना फिर कभी password नहीं माँगता। Private key आपके computer पर रहती है और कभी transmit नहीं होती; सिर्फ matching public key को GitHub, GitLab, या Bitbucket पर upload करना होता है।

उदाहरण: Why Use SSH with Git

bash
ssh-keygen -t ed25519 -C "[email protected]"

GitHub Account में SSH Key Add करना

Generate होने के बाद, public key (.pub file) को आपके Git hosting provider के SSH-keys settings page में paste करना ज़रूरी है -- provider फिर इसे future connections verify करने के लिए इस्तेमाल करता है, कभी आपकी private key देखे बिना। GitHub पर specifically, Settings > SSH and GPG keys > New SSH key खोलें, .pub file से public key Key field में paste करें, इसे एक descriptive title दें, और save करें -- GitHub फिर इस machine से हर future SSH connection के लिए उस key पर भरोसा करता है, और same key को GitHub CLI इस्तेमाल करके terminal से भी add किया जा सकता है।

उदाहरण: Adding SSH Key to GitHub Account

bash
cat ~/.ssh/id_ed25519.pub
# paste into GitHub Settings > SSH and GPG keys

Connection Test करना

Real work के लिए SSH पर भरोसा करने से पहले, यह confirm करना उचित है कि handshake actually succeed होता है -- GitHub और GitLab दोनों एक special test endpoint expose करते हैं जो आपकी key authenticate करता है और shell access देने के बजाय एक friendly message से reply करता है।

उदाहरण: Testing the Connection

bash
ssh -T [email protected]

एक Remote को SSH में बदलना

जो repository आपने originally HTTPS से clone की थी वह हर future push और pull के लिए HTTPS इस्तेमाल करती रहती है जब तक आप explicitly इसका remote URL इसके बजाय SSH address पर point न करें -- इस switch के लिए repository दोबारा clone करने की ज़रूरत नहीं।

उदाहरण: Switching a Remote to SSH

bash
git remote set-url origin [email protected]:user/repo.git

कई Keys Manage करना

कई accounts में काम करने वाले developers -- उदाहरण के लिए, एक personal GitHub और एक work GitLab -- आमतौर पर हर account के लिए एक अलग key pair generate करते हैं और हर एक को इसके host से एक SSH config file इस्तेमाल करके map करते हैं, हर जगह एक key reuse करने के बजाय।

उदाहरण: Managing Multiple Keys

bash
# ~/.ssh/config
Host github.com-work
  HostName github.com
  IdentityFile ~/.ssh/id_ed25519_work
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. GitHub में key add करते समय public id_ed25519.pub के बजाय private key जैसे id_ed25519 share करना।
  2. एक https:// URL से clone करना और SSH इस्तेमाल होने की उम्मीद करना, जबकि remote [email protected]:user/repo.git form में होना ज़रूरी है।
  3. setup के बाद ssh -T [email protected] skip करना, ताकि एक गलत key या एक missing ssh-agent सिर्फ तब discover हो जब एक push fail हो।
चैप्टर सारांश
  • Git एक version control system है, और यह chapter इसकी history, features, installation, और configuration cover करता है।
  • आप एक पहली repository बनाते हैं और overall workflow सीखते हैं।
  • SSH setup remote repositories तक secure access allow करता है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.