Git SSH Setup
In this page:
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
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
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
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
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
# ~/.ssh/config
Host github.com-work
HostName github.com
IdentityFile ~/.ssh/id_ed25519_work
- GitHub में key add करते समय public
id_ed25519.pubके बजाय private key जैसेid_ed25519share करना। - एक
https://URL से clone करना और SSH इस्तेमाल होने की उम्मीद करना, जबकि remote[email protected]:user/repo.gitform में होना ज़रूरी है। - setup के बाद
ssh -T [email protected]skip करना, ताकि एक गलत key या एक missingssh-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: