Featured image of post Linux 產生 SSH Key

Linux 產生 SSH Key

Generate an SSH Key

前言

SSH Key 是一種基於加密的身份驗證方式,常用於遠端連線伺服器或版本控制系統(如 Git)。以下是如何在 Linux 系統上快速生成 SSH Key 的步驟。

主要

打開 Terminal 並執行指令

首先,開啟 Terminal 並執行以下指令來產生新的 SSH Key:

1
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

指令說明:

  • ssh-keygen:產生 SSH 金鑰的工具。
  • -t rsa:指定使用 RSA 演算法生成金鑰。
  • -b 4096:設定金鑰長度為 4096 位元,以提升安全性。
  • -C “your_email@example.com”:附加一個 email 作為此金鑰的識別標籤。

指定存放位置

執行指令後,系統會詢問是否要儲存金鑰至預設路徑(~/.ssh/id_rsa)。如果接受預設路徑,直接按下 Enter;
若希望存到其他路徑,則可手動指定路徑。

1
Enter file in which to save the key (/home/username/.ssh/id_rsa):

設定密碼(選填)

接著會提示是否為 SSH Key 設定密碼。這是額外的安全層,若設置密碼,在使用 SSH Key 時需要輸入該密碼。
若不需要密碼,按下 Enter 跳過此步驟。

1
Enter passphrase (empty for no passphrase):

完成並確認金鑰生成

完成上述步驟後,系統會生成一組公鑰(id_rsa.pub)和私鑰(id_rsa), 分別儲存在 ~/.ssh 目錄下。您可以使用以下命令檢視生成的公鑰:

查看公鑰

1
cat ~/.ssh/id_rsa.pub
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy