柚子快報激活碼778899分享:運維 git配置ssh key
柚子快報激活碼778899分享:運維 git配置ssh key
一、生成ssh公鑰和私鑰對
? ? ? ? 打開終端,輸入命令,-C 后是git郵箱,在?Enter file in which to save the key (/home/my/.ssh/id_rsa): 后可以輸入公鑰和私鑰對保存路徑及文件名,默認(rèn)是 /home/my/.ssh/id_rsa,其它的全部按回車即可。(公鑰和私鑰對保存路徑及文件名不是默認(rèn)的需要配置 config)
my@ubuntu:~$ ssh-keygen -t rsa -C '84848493@qq.com'
Generating public/private rsa key pair.
Enter file in which to save the key (/home/my/.ssh/id_rsa): /home/my/.ssh/id_rsa_ldc
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/my/.ssh/id_rsa_ldc
Your public key has been saved in /home/my/.ssh/id_rsa_ldc.pub
The key fingerprint is:
SHA256:O2EBiWUW+VyztfbRIC7wMN1s0sNHJu6heCVdL+X86bg chenchuanhai@ldcems.com
The key's randomart image is:
+---[RSA 3072]----+
| o*+ . =..+ .|
| .oo.+ =oX+o= |
| o.*.B==.o+|
| oo+=+...+|
| S oo.. o.|
| . + + |
| o . . |
| . . |
| E |
+----[SHA256]-----+
my@ubuntu:~/.ssh$
二、添加SSH密鑰
? ? ? ? 1. 打開~/.ssh/id_rsa.pub文件(~表示用戶目錄,比如我的windows就是C:\Users\Administrator),復(fù)制其中的內(nèi)容。
? ? ? ? 2. 打開見面,登錄git,找到 用戶設(shè)置——>SSH密鑰,如下圖所示。
? ? ? ? 至此,如果生成的公鑰和私鑰對是默認(rèn)路徑,便可以通過?git clone ssh://git@gitlab.com/myproject.git來訪問了。
三、config
? ? ? ? 當(dāng)生成的公鑰和私鑰對不是默認(rèn)路徑或者你需要多個git服務(wù)器時,需要配置config文件。打開文件。
vim ~/.ssh/config
? ? ? ? 在文件中輸入以下內(nèi)容
# gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_id-rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id-rsa
# gitlab.my.com
Host gitlab.my.com
HostName 192.168.10.183
Port 9022
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_my
?
# 配置文件參數(shù)
# Host : Host可以看作是一個你要識別的模式,對識別的模式,進(jìn)行配置對應(yīng)的的主機(jī)名和ssh文件
# HostName : 要登錄主機(jī)的主機(jī)名
# User : 登錄名
# IdentityFile : 指明上面User對應(yīng)的identityFile路徑
# Port : 端口
? ? ? ? 對于gitlab.my.com中由于主機(jī)名是ip,需要配置hosts,打開hosts文件
sudo vim etc/hosts
? ? ? ? 添加一行
192.168.10.183 gitlab.my.com
? ? ? ? 訪問時使用:git clone?ssh://git@gitlab.my.com:9022/myproject.git
四、驗證
ssh-keygen -R 172.22.195.183
ssh -p 8022 git@172.22.195.183
example:
cch@ldc:~/work/notes$ ssh git@gitee.com
Hi 奮斗的cch(@struggling-cch)! You've successfully authenticated, but GITEE.COM does not provide shell access.
Connection to gitee.com closed.
柚子快報激活碼778899分享:運維 git配置ssh key
好文閱讀
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。