iT邦幫忙

2025 iThome 鐵人賽

DAY 21
0

SSH Key 是什麼?

SSH Key 是一對 加密金鑰(Key Pair),分成:

  • 私鑰 (Private Key):放在你的電腦,不能外洩。 鑰匙
  • 公鑰 (Public Key):可以公開,交給伺服器(例如 GitHub)。 鎖頭

鎖頭和鑰匙有對應到,才可以做專案的推送。需要在本機建立 SSH Key,並把公鑰綁定到 Github 帳號中。
若有其他電腦裝置也要使用,也要生成一把新的鑰匙和鎖頭。一個 Github 帳號中可以有很多鎖頭和鑰匙。
當一台電腦有不同 github 帳號時,可以在不同帳號建立不同的 SSH Key 做使用。

https://ithelp.ithome.com.tw/upload/images/20251004/20178581AeUvhs5Xdv.png

在 github clone 專案時,一種是 https 可以快速下載,但每次 git push 時,需要輸入帳密;另外一種是在本機建立SSH Key,登記到 GitHub 帳號去做綁定,讓本機上的專案和遠端 git 常態的連動推送。

https://ithelp.ithome.com.tw/upload/images/20251004/20178581YON8QB9lQA.png

https://ithelp.ithome.com.tw/upload/images/20251004/20178581Qs9xBX1nCg.png

建立 SSH Key 指令

https://ithelp.ithome.com.tw/upload/images/20251004/20178581Sf8HSyx1kw.png
https://ithelp.ithome.com.tw/upload/images/20251004/20178581TPpJzs374e.png

ls -la ~/.ssh
https://ithelp.ithome.com.tw/upload/images/20251004/20178581lbJoQOzkfP.png

nano ~/.ssh/config
因為我有兩個github帳號,一個是私人用,一個是公司用,所以需要建立兩個SSH Key,各自綁定到兩個不同的帳號上
要記得為本機的登入環境添加私鑰,否則push不上去!

常用 Git 指令

  • 推拉指令
    https://ithelp.ithome.com.tw/upload/images/20251004/201785819SnuUmwXfw.png

  • 查看狀態
    https://ithelp.ithome.com.tw/upload/images/20251004/20178581axEJynQFfA.png

  • 切換分支
    https://ithelp.ithome.com.tw/upload/images/20251004/20178581QjV1zoMGH7.png

  • 暫存檔案
    https://ithelp.ithome.com.tw/upload/images/20251004/201785813sl54UNF78.png
    https://ithelp.ithome.com.tw/upload/images/20251004/20178581HdbFWgTEC8.png

  • 合併分支
    https://ithelp.ithome.com.tw/upload/images/20251004/20178581qvP94sDD0h.png

好,得先把專案推上 github 才可以部署上線呀!


上一篇
Day 20 動態內容:用 Github api 自動化更新 Projects 資訊
系列文
《運用通勤時間打造線上履歷作品集:30 天 Nuxt 自我挑戰》21
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言