DEV Community

Javohir Aliyev
Javohir Aliyev

Posted on

Git Account'ga SSH orqali ulanish

Hammaga salom, bugun sizlar bilan GitHub’ga SSH orqali ulanish haqida bilganlarimnini bo’lishaman!

❓ Nega o’zi SSH ishlatish kerak?
Bilasiz, GitHub’dan oddiy HTTP orqali ham foydalanish mumkin, lekin bu uchun doimiy parollarni qaytadan terib yurish kerak (va bu juda oddiy ham). SSH ishlatish esa bizga ko’proq xavfsizlik va qulaylik beradi, garchi boshlanishida ozgina qiyinroq bo’lsa-da.

🆕 Avvaliga, o’zimizni qurilmamizda SSH kalit yaratib olishimiz kerak, ya’ni biz kompyuterimizni GitHubga tanitib olish uchun ikkalasiga bitta unique kalit yasab olamiz, va buning uchun avval

cd ~/.ssh 
Enter fullscreen mode Exit fullscreen mode

“Enter”ni bosib yuqoridagi kodni kiritgandan keyin esa quyidagi buyruqni “command line” ga kiritamiz:

ssh-keygen -t ed25519 -C "your_email@example.com"

Enter fullscreen mode Exit fullscreen mode

Bu buyruqni kiritganimizdan so’ng, shell bizdan kalitni nima deb nomlangan faylga joylashimizni aytishimizni so’raydi, bu joyida xohlagan narsani kiritish mumkin. Men ismimni kiritganman.

🔩 Endi esa, https://github.com/settings/ssh/new ga kirib, Titlega o’zimiz xohlagan nomni beramiz, pastidagi Key maydoniga esa boyagina .ssh papkada yaratgan .pub faylimizni ichidagi kalitni kiritamiz va saqlaymiz. Vualya, SSH Gitga muvaffaqiyatli qo’shildi, lekin bu doim ham shu joyidan boshlab ishlab ketavermaydi. Bo’lishi mumkin bo’lgan bir nechta muammolarni ko’rib chiqamiz ⏬

🔌 Yuqorida aytilgan ishlarni qilgandan so’ng, agar bizni qurilmada OpenSSH xizmati yoqilmagan bo’lsa har xil muammolar chiqib kelaverishi mumkin, shuning uchun boshqa muammolarga o’tishdan avval shuni tushuntiraman. Quyidagi ketma-ketlikni qilamiz:

  1. Windows + R
  2. services.msc, va OK
  3. OpenSSH Authentication Agent’ni topamiz
  4. Mouse’ni o’ng tarafini bosib, properties’ga kiramiz
  5. Startupe type’ni Automaticga o’tkazamiz
  6. Bo’ldi!

🧪 Bularni qilgandan keyin birorta repository’ni SSH orqali clone qilishga harakat qilib ko’ring, agar hammasi o’xshasa, o’qishni shu yerda to’xtatishingiz mumkin.

🆘 Agar Terminal(biz boshida ochgan powershell yoki cmd)’da

`git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.`

Please make sure you have the correct access rights
and the repository exists.

degan ogohlantirish ko’rsangiz quyidagicha ketma-ketlikni bajaring:

ssh -vT git@github.com
Enter fullscreen mode Exit fullscreen mode

Yuqoridagi komandani xuddi shundayligicha terminalga kiriting, agar undan keyingi javobda Hi USERNAME! You've successfully authenticated... degan yozuvni ko’rishingiz kerak.

Agar buni o’rniga tepadagi muammo yana takrorlansa,

ssh-add -l -E sha256

Enter fullscreen mode Exit fullscreen mode

buyrug’ini Terminalga kiritib SSH kalit qo’shilgan qo’shilmaganini tekshiring, bundan keyin bizda

2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)

Enter fullscreen mode Exit fullscreen mode

ga o’xshagan narsa chiqishi kerak!

Unday bo’lmasa, ssh-add buyrug’ini kiritamiz terminalga. (bu paytda .ssh papkada bo’lishimiz, yoki ssh-add’dan keyin o’sha .pub faylni joylashuvini yozish kerak). Bundan keyin terminal sizga ssh kalit tizimga qo’shilganini aytadi, lekin bu bilan chegaralanmaymiz. Shundan keyin bizda ssh-add -l -E sha256 komandasidan keyin biz kutgan javob kelishi kerak.

🩸💉 Bulardan so’ng, ssh -T [git@github.com](mailto:git@github.com) komandasini yana bir marta kiritamiz, bu safar tizim bizdan qon topshirishni so’raydi, “yes” deb javob beramiz. Vualya, endi

Hi JavohirAliyev! You've successfully authenticated, but GitHub does not provide shell access
Enter fullscreen mode Exit fullscreen mode

ga o’xshagan narsa ko’rishimiz kerak :)

Keyin esa, quyidagi komandani kiritamiz connection’ni verify qilish uchun:

ssh -vT [git@github.com](mailto:git@github.com)
Enter fullscreen mode Exit fullscreen mode

Oxirida mana bunaqa narsa ko’rishimiz kerak:

Hi JavohirAliyev! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2032, received 2608 bytes, in 0.4 seconds
Bytes per second: sent 4896.4, received 6284.3
debug1: Exit status 1

OZGINA QOLDI….

🔁 Endi hammasi joyida bo’lishi kerak, faqat keyingi safar hammasini qayta qilmaslik uchun yana bir ikkita komandalar bilan avtomatlashtiramiz connection’ni:

Start-Service ssh-agent | Set-Service -StartupType Automatic
Enter fullscreen mode Exit fullscreen mode
Start-Service ssh-agent
Enter fullscreen mode Exit fullscreen mode
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'”
Enter fullscreen mode Exit fullscreen mode

Tugadi! Agar shundan keyin ham sizda bu bilan bog’liq muammolar davom etsa, muammoni to’liq tasvirlab, nimalar qilib ko’rganingizni aytib uni batavsil tushuntiring. Postga o’zgartirishlar kiritilib, uni takomillashtirilishi uni ko’proq odamlarga foydali qiladi.

Top comments (0)