Git SSH金鑰生成

2021-09-22 12:44:37 字數 2415 閱讀 9393

ssh金鑰允許您在計算機和gitlab之間建立安全連線。在shell中生成ssh金鑰之前,請通過執行以下命令檢查您的系統是否已有ssh金鑰:

windows命令列:

type %userprofile%\.ssh\id_rsa.pub
gnu / linux的/ mac / powershell的:

cat ~/.ssh/id_rsa.pub
如果您看到以字串開頭的長字串ssh-rsa,則可以跳過該ssh-keygen步驟。

注意:最佳做法是使用ssh密碼的密碼,但這不是必需的,您可以通過按enter鍵跳過建立密碼。請注意,您在此處選擇的密碼無法更改或檢索。

要生成新的ssh金鑰,請使用以下命令:

ssh-keygen -t rsa -c "你的email位址"
此命令將提示您輸入位置和檔名以儲存金鑰對和密碼。當提示輸入位置和檔名時,只需按enter鍵即可使用預設值。如果使用其他名稱,則不會自動使用該金鑰。

使用以下命令顯示您的公鑰:

windows命令列:

type %userprofile%\.ssh\id_rsa.pub
gnu / linux的/ mac / powershell的:

cat ~/.ssh/id_rsa.pub
將金鑰複製貼上到使用者配置檔案中「ssh」選項卡下的「我的ssh金鑰」部分。請從ssh-rsa您的使用者名稱和主機開始複製完整的金鑰。

要將公鑰複製到剪貼簿,請使用以下**。根據您的作業系統,您需要使用不同的命令:

windows命令列:

type %userprofile%\.ssh\id_rsa.pub | clip
windows powershell:

cat ~/.ssh/id_rsa.pub | clip
蘋果電腦:

pbcopy < ~/.ssh/id_rsa.pub
gnu / linux(需要xclip):

xclip -sel clip < ~/.ssh/id_rsa.pub
部署金鑰允許使用單個ssh金鑰對多個專案進行唯讀訪問。

這對於將儲存庫轉殖到continuous integration(ci)伺服器非常有用。通過使用部署金鑰,您不必設定虛擬使用者帳戶。

如果您是專案主資料或所有者,則可以在「部署金鑰」部分下的專案設定中新增部署金鑰。按「新建部署金鑰」按鈕並上傳公共ssh金鑰。在此之後,使用相應私鑰的計算機具有對專案的唯讀訪問許可權。

部署金鑰可以在專案之間共享,您只需將它們新增到每個專案中。

如何將您的ssh金鑰新增到eclipse:https:

無論出於何種原因,如果您決定為gitlab ssh金鑰對指定非預設位置和檔名,則必須配置ssh客戶端以找到gitlab ssh私鑰以連線到gitlab伺服器(可能是gitlab.com)。對於openssh客戶端,這將在~/.ssh/config檔案中處理,其節類似於以下內容:

#

# main gitlab.com server

#host gitlab.com

rsaauthentication yes

identityfile ~/my-ssh-key-directory/my-gitlab-private-key-filename

user mygitlabusername

另乙個例子

#

# our company's internal gitlab server

#host my-gitlab.company.com

rsaauthentication yes

identityfile ~/my-ssh-key-directory/company-com-private-key-filename

請注意,在上面的gitlab.com示例中,指定了使用者名稱來覆蓋openssh選擇的預設值(您的本地使用者名)。僅當您的本地和遠端使用者名稱不同時才需要此選項。

由於ssh客戶端種類繁多,配置選項非常多,因此對這些主題的進一步說明超出了本文件的範圍。

公共ssh金鑰必須是唯一的,因為它們將繫結到您的帳戶。您的ssh金鑰是通過ssh推送**時唯一的識別符號。這就是它需要唯一對映到單個使用者的原因。

本地 git ssh 金鑰配置方案

1 生成ssh公鑰ssh keygen t rsa c xx xx.com 2 檢視 public key,並把他新增到碼雲 gitee.com ssh key 企業版 參考 碼雲push時提示 deploykey does not support push code fatal could not...

Linux生成金鑰

大家可以配置成密論認證的方式 首先生成金鑰,用命令ssh keygen t rsa 執行後可以一直空格,生成金鑰,id rsa和id rsa.pub檔案 預設放在 root ssh 下,ssh檔案是隱藏的,要顯示隱藏檔案才看得到 在 home admin下建立.ssh活頁夾,把id rsa.pub檔...

生成金鑰方法

生成私鑰 openssl genrsa out rsa private key.pem 1024 根據私鑰生成公鑰簽名證書 openssl req new x509 days 3650 key rsa private key.pem out ppmoney key.crt keytool expor...