CentOS 8 ( 虛擬機 )
進到 GitLab 網頁管理介面會看到以下訊息
You won't be able to pull or push project code via SSH until you add an SSH key to your profile
預設我們只能透過 http 或是 https 來把 GitLab 檔案上傳與下載.
[root@localhost ~]# git clone git@192.168.31.140:ben/runner_test.git Cloning into 'runner_test'... The authenticity of host '192.168.31.140 (192.168.31.140)' can't be established. ECDSA key fingerprint is SHA256:mu3vJ57wIW2fHfX6QsXvLuIlMUalUkfRIlpOKRtB2fo. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.31.140' (ECDSA) to the list of known hosts. git@192.168.31.140's password: Permission denied, please try again. git@192.168.31.140's password: Permission denied, please try again. git@192.168.31.140's password: git@192.168.31.140: Permission denied (publickey,password). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
我們只需要把使用者端產生的 SSH 的 公鑰 放到 GitLab 網頁並儲存起來即可,關於 SSH 公/私金鑰 請參考 – https://benjr.tw/98344
透過 ssh-keygen 來產生 SSH 公私鑰 ,這邊不使用 passhrase (需要一串密碼來解開私鑰) , -C 後面名稱可以使用 E-Mail 或是姓名皆可.
[root@localhost ~]# ssh-keygen -t rsa -C ben@gmail.com Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:jbZqlgzXm8VHXyGzUkjmn/huqmxm6XzB4wAcSB6yg2k ben@gmail.com The key's randomart image is: +---[RSA 3072]----+ | ..o. .o. | | o +... o. + . | | E o .. . .. + .| |. . o o .+.. .| | .S.oo.+ . | | . ...oo+o . | | + ..++.o. | | =.== o.. | | o. ==o.o. | +----[SHA256]-----+
SSH 產生的 公/私金鑰 皆儲存在 .ssh 目錄裡面.
[root@localhost ~]# ll .ssh/ id_rsa id_rsa.pub known_hosts
id_rsa.pub 就是公鑰,內容要複製到 GitLab 網頁並儲存起來.
[root@localhost ~]# cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDKcNJjUm3c2O3Wcfzr8f3LGQtv3kS4bwwY1dwuZBXnFSmYZX3d+ZH7ogDMr1itFoJfYZRclih0Yq9ZNhJkDjxxrKFuey8doAfZxNT7REzJYNZoByLTvbo4Cz+cpmNwFUVDhV8QlDbRteFmS8dFIC0NAfFpe34kcO21wI4yhqAkqnyD3/R4ONDQqYSs1dF9Xyz7Trtergt34524m534-jgmerlom3-54yrthghhhrth46uy64hjgh45tym,0fgjk3-54FgcnuvHsKjQVwwm7yPGddKNpm03bFcfbIFFQe2PpGqOw0C+qvCp//dFOZosSJ2NnjZv+Q3zQ9kR8qsNLyTHF63XUP6VvRTmQLik8yLEH21LnEUfegJIka9qiJJ+vrh4hkT1zNIb1s7Ax7YaRGPA2BhNtXo9YIUAcvjaX5pZGMwQZt8DRGjvYV6/0= ben@gmail.com
我這邊使用 ben 身分登入 GitLab 網頁,並點選 User Settings / SSH Keys .
把剛剛的 id_rsa.pub 內容貼到網頁的 Key 裡面 ,並點選 Add Key 儲存起來.
這樣在使用者端就不再需要帳號密碼才能下載檔案了.
[root@localhost ~]# git clone git@192.168.31.140:ben/runner_test.git Cloning into 'runner_test'... remote: Enumerating objects: 7, done. remote: Total 7 (delta 0), reused 0 (delta 0), pack-reused 7 Receiving objects: 100% (7/7), done.
沒有解決問題,試試搜尋本站其他內容