<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Fast lookup of authorized SSH keys in the database > 原文:[https://docs.gitlab.com/ee/administration/operations/fast_ssh_key_lookup.html](https://docs.gitlab.com/ee/administration/operations/fast_ssh_key_lookup.html) * [Fast lookup is required for Geo](#fast-lookup-is-required-for-geo-premium) * [Setting up fast lookup via GitLab Shell](#setting-up-fast-lookup-via-gitlab-shell) * [How to go back to using the `authorized_keys` file](#how-to-go-back-to-using-the-authorized_keys-file) * [Compiling a custom version of OpenSSH for CentOS 6](#compiling-a-custom-version-of-openssh-for-centos-6) * [SELinux support and limitations](#selinux-support-and-limitations) # Fast lookup of authorized SSH keys in the database[](#fast-lookup-of-authorized-ssh-keys-in-the-database "Permalink") 版本歷史 * 在[GitLab Starter](https://about.gitlab.com/pricing/) 9.3 中[引入](https://gitlab.com/gitlab-org/gitlab/-/issues/1631) . * [在](https://gitlab.com/gitlab-org/gitlab/-/issues/3953) GitLab 社區版 10.4 中[可用](https://gitlab.com/gitlab-org/gitlab/-/issues/3953) . **注意:**本文檔介紹了`authorized_keys`文件的替代品. 對于普通(非部署密鑰)用戶,請考慮使用[SSH 證書](ssh_certificates.html) . 它們甚至更快,但不是臨時替代品. 隨著用戶數量的增加,常規的 SSH 操作變得緩慢,這是因為 OpenSSH 通過線性搜索來搜索授權用戶的密鑰. 在最壞的情況下,例如,當用戶無權訪問 GitLab 時,OpenSSH 將掃描整個文件以搜索密鑰. 這會花費大量時間和磁盤 I / O,這將延遲用戶嘗試推送或拉到存儲庫的時間. 更糟糕的是,如果用戶頻繁添加或刪除密鑰,則操作系統可能無法緩存`authorized_keys`文件,這將導致磁盤被重復訪問. GitLab Shell 通過提供一種通過 GitLab 數據庫中的快速索引查找來授權 SSH 用戶的方法來解決此問題. 本頁介紹如何啟用快速查找授權的 SSH 密鑰. > **警告:**由于`AuthorizedKeysCommand`必須能夠接受指紋,因此需要 OpenSSH 6.9+版本. 這些說明將中斷使用較舊版本的 OpenSSH 的安裝,例如截至 2017 年 9 月的 CentOS 6 附帶的安裝.如果要將此功能用于 CentOS 6,請遵循[有關如何構建和安裝自定義 OpenSSH 軟件包的說明](#compiling-a-custom-version-of-openssh-for-centos-6) . ## Fast lookup is required for Geo[](#fast-lookup-is-required-for-geo-premium "Permalink") 默認情況下,GitLab 管理一個`authorized_keys`文件,其中包含允許訪問 GitLab 的用戶的所有公共 SSH 密鑰. 但是,為了維護單個事實來源,需要將[Geo](../geo/replication/index.html)配置為通過數據庫查找執行 SSH 指紋查找. 作為[設置 Geo 的](../geo/replication/index.html#setup-instructions)一部分,您將需要對主節點和輔助節點都遵循以下概述的步驟,但是請注意,只需在主節點上取消選中`Write to "authorized keys" file`復選框,因為它將被選中.如果數據庫復制正在工作,則會自動在輔助服務器上反映出來. ## Setting up fast lookup via GitLab Shell[](#setting-up-fast-lookup-via-gitlab-shell "Permalink") GitLab Shell 提供了一種通過對 GitLab 數據庫進行快速索引查找來授權 SSH 用戶的方法. GitLab Shell 使用 SSH 密鑰的指紋來檢查用戶是否有權訪問 GitLab. 將以下內容添加到您的`sshd_config`文件中. 通常位于`/etc/ssh/sshd_config` ,但如果使用 Omnibus Docker,它將為`/assets/sshd_config` : ``` Match User git # Apply the AuthorizedKeysCommands to the git user only AuthorizedKeysCommand /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell-authorized-keys-check git %u %k AuthorizedKeysCommandUser git Match all # End match, settings apply to all users again ``` 重新加載 OpenSSH: ``` # Debian or Ubuntu installations sudo service ssh reload # CentOS installations sudo service sshd reload ``` 通過注釋掉您在`authorized_keys`中的用戶密鑰(以`#`開頭以對其進行注釋),并嘗試拉出存儲庫來確認 SSH 是否正常工作. A successful pull would mean that GitLab was able to find the key in the database, since it is not present in the file anymore. **注意:**對于 Omnibus Docker,默認情況下在 GitLab 11.11 及更高版本中設置了`AuthorizedKeysCommand` .**注意:**對于從源安裝,該命令位于`/home/git/gitlab-shell/bin/gitlab-shell-authorized-keys-check`是否遵循[從源安裝的](../../install/installation.html#install-gitlab-shell)說明. 您可能要考慮在其他地方創建包裝腳本,因為此命令需要由`root`擁有,而不能由 group 或其他用戶寫入. 您也可以考慮根據需要更改此命令的所有權,但這可能需要在`gitlab-shell`升級期間臨時更改所有權.**注意:**在確認 SSH 可以正常工作之前,請不要禁用寫操作,因為該文件很快就會過時. In the case of lookup failures (which are common), the `authorized_keys` file will still be scanned. So Git SSH performance will still be slow for many users as long as a large file exists. 您可以通過取消選中 GitLab 安裝的`Write to "authorized_keys" file` **管理區域">"設置">"網絡">"性能優化** `Write to "authorized_keys" file`中的`Write to "authorized_keys" file`來禁用對`authorized_keys`文件的更多寫入. [![Write to authorized keys setting](https://img.kancloud.cn/a0/8b/a08b6bdc44256457362b227bb9c39c02_2674x372.png)](img/write_to_authorized_keys_setting.png) 再次,通過在 UI 中刪除用戶的 SSH 密鑰,添加一個新的 SSH 密鑰,然后嘗試提取存儲庫來確認 SSH 是否正常工作. 然后,您可以備份和刪除您的`authorized_keys`文件以獲得最佳性能. 當前用戶的密鑰已經存在于數據庫中,因此無需遷移或要求用戶重新添加其密鑰. ## How to go back to using the `authorized_keys` file[](#how-to-go-back-to-using-the-authorized_keys-file "Permalink") 這是一個簡短的概述. 請參閱以上說明以獲取更多上下文. 1. [Rebuild the `authorized_keys` file](../raketasks/maintenance.html#rebuild-authorized_keys-file) 2. 啟用對"應用程序設置"中的`authorized_keys`文件的寫入 3. 如果使用的是 Omnibus Docker,請從`/etc/ssh/sshd_config`或`/assets/sshd_config`刪除`AuthorizedKeysCommand`行. 4. Reload `sshd`: `sudo service sshd reload` 5. 刪除`/opt/gitlab-shell/authorized_keys`文件 ## Compiling a custom version of OpenSSH for CentOS 6[](#compiling-a-custom-version-of-openssh-for-centos-6 "Permalink") 對于 Ubuntu 16.04 用戶而言,無需構建自定義版本的 OpenSSH,因為 Ubuntu 16.04 隨 OpenSSH 7.2 一起提供. CentOS 7.4 用戶也不需要,因為該版本隨 OpenSSH 7.4 一起提供. 如果您使用的是 CentOS 7.0-7.3,我們強烈建議您升級到 CentOS 7.4,而不要遵循此過程. 這應該和運行`yum update`一樣簡單. CentOS 6 用戶必須構建自己的 OpenSSH 軟件包才能通過數據庫啟用 SSH 查找. 以下說明可用于構建 OpenSSH 7.5: 1. 首先,下載軟件包并安裝所需的軟件包: ``` sudo su - cd /tmp curl --remote-name https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.5p1.tar.gz tar xzvf openssh-7.5p1.tar.gz yum install rpm-build gcc make wget openssl-devel krb5-devel pam-devel libX11-devel xmkmf libXt-devel ``` 2. 通過將文件復制到正確的位置來準備構建: ``` mkdir -p /root/rpmbuild/{SOURCES,SPECS} cp ./openssh-7.5p1/contrib/redhat/openssh.spec /root/rpmbuild/SPECS/ cp openssh-7.5p1.tar.gz /root/rpmbuild/SOURCES/ cd /root/rpmbuild/SPECS ``` 3. 接下來,正確設置規格設置: ``` sed -i -e "s/%define no_gnome_askpass 0/%define no_gnome_askpass 1/g" openssh.spec sed -i -e "s/%define no_x11_askpass 0/%define no_x11_askpass 1/g" openssh.spec sed -i -e "s/BuildPreReq/BuildRequires/g" openssh.spec ``` 4. 建立 RPM: ``` rpmbuild -bb openssh.spec ``` 5. 確保已構建 RPM: ``` ls -al /root/rpmbuild/RPMS/x86_64/ ``` 您應該看到以下內容: ``` total 1324 drwxr-xr-x. 2 root root 4096 Jun 20 19:37 . drwxr-xr-x. 3 root root 19 Jun 20 19:37 .. -rw-r--r--. 1 root root 470828 Jun 20 19:37 openssh-7.5p1-1.x86_64.rpm -rw-r--r--. 1 root root 490716 Jun 20 19:37 openssh-clients-7.5p1-1.x86_64.rpm -rw-r--r--. 1 root root 17020 Jun 20 19:37 openssh-debuginfo-7.5p1-1.x86_64.rpm -rw-r--r--. 1 root root 367516 Jun 20 19:37 openssh-server-7.5p1-1.x86_64.rpm ``` 6. 安裝軟件包. OpenSSH 軟件包將用其自己的版本替換`/etc/pam.d/sshd` ,這可能會阻止用戶登錄,因此請確保在安裝后備份并還原了該文件: ``` timestamp=$(date +%s) cp /etc/pam.d/sshd pam-ssh-conf-$timestamp rpm -Uvh /root/rpmbuild/RPMS/x86_64/*.rpm yes | cp pam-ssh-conf-$timestamp /etc/pam.d/sshd ``` 7. 驗證安裝的版本. 在另一個窗口中,嘗試登錄到服務器: ``` ssh -v <your-centos-machine> ``` 您應該看到以下一行:" debug1:遠程協議版本 2.0,遠程軟件版本 OpenSSH_7.5" 如果沒有,則可能需要重新啟動`sshd` (例如`systemctl restart sshd.service` ). 8. *重要!* 退出之前,請打開與服務器的新 SSH 會話,以確保一切正常! 如果您需要降級,只需安裝較舊的軟件包即可: ``` # Only run this if you run into a problem logging in yum downgrade openssh-server openssh openssh-clients ``` ## SELinux support and limitations[](#selinux-support-and-limitations "Permalink") 在 GitLab 10.5 中[引入](https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/2855) . GitLab 支持[SELinux 的](https://en.wikipedia.org/wiki/Security-Enhanced_Linux) `authorized_keys`數據庫查詢. 由于 SELinux 策略是靜態的,因此 GitLab 目前不支持更改內部 Unicorn 端口的功能. 管理員必須為環境創建一個特殊的`.te`文件,因為它不是動態生成的.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看