To create a new SSH key pair:
1. Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.
2. Generate a new ED25519 SSH key pair: ssh-keygen -t ed25519 -C "email@example.com"
2.1 Or, if you want to use RSA: ssh-keygen -o -t rsa -b 4096 -C "email@example.com"
3. Next, you will be prompted to input a file path to save your SSH key pair to... use the suggested path by pressing Enter
4. Once the path is decided, you will be prompted to input a password to secure your new SSH key pair. It's a best practice to use a password, but it's not required and you can skip creating it by pressing Enter twice.
5. Copy your public SSH key to the clipboard by using one of the commands below depending on your Operating System:
macOS: pbcopy < ~/.ssh/id_ed25519.pub
WSL / GNU/Linux (requires the xclip package): xclip -sel clip < ~/.ssh/id_ed25519.pub
Git Bash on Windows: cat ~/.ssh/id_ed25519.pub | clip
6. Navigating to SSH Keys and pasting your public key in the Key field
7. Click the Add key button
尝试使用git clone XXX,如果你看到LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to XXX,它可能是刚刚更新了你的操作系统,安装了一些开发工具,例如Xcode及其在Mac上的工具,VPN,反病毒(特别是卡巴斯基反病毒)或其他之间的东西。
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
通过在UI中删除用户的SSH密钥,添加一个新的密钥,并尝试拉出一个repo来确认SSH正在工作。
默认情况下(我们安装时的默认),写入authorized_keys文件在Admin Area >性能优化设置中被检查。因此,我们未选中该选项,转而使用Gitlab数据库。