You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置SSH密钥后GitLab仍要求输入密码,求解决方法

Fixes for GitLab SSH Key Setup Still Asking for Password

Let me break down the most common reasons this happens and how to fix them— I’ve sorted out this exact issue for plenty of developers before!

  • Check if your remote repo uses SSH (not HTTPS)
    Even if you set up SSH keys, Git will still ask for a password if your remote is using the HTTPS URL. Run this command to check your remote addresses:

    git remote -v
    

    If you see something like https://gitlab.com/your-username/your-repo.git, you need to switch it to the SSH format. Use this command (replace placeholders with your actual username and repo name):

    git remote set-url origin git@gitlab.com:your-username/your-repo.git
    
  • Verify your SSH key is properly added to GitLab
    Double-check that your local public key is registered in your GitLab account:

    1. Print your public key content (use the correct filename if you named your key something else):
      cat ~/.ssh/id_rsa.pub
      
    2. Go to your GitLab account settings → SSH Keys and make sure this exact key is listed, hasn’t expired, and has no typos.
  • Test your SSH connection to GitLab
    Run this command to confirm your SSH setup works:

    ssh -T git@gitlab.com
    

    If you get a message like Welcome to GitLab, @your-username!, your connection is good. If not:

    • Fix file permissions (SSH is picky about this):
      chmod 700 ~/.ssh
      chmod 600 ~/.ssh/id_rsa
      
    • Load your key into the SSH agent:
      eval "$(ssh-agent -s)"
      ssh-add ~/.ssh/id_rsa
      
  • Resolve multiple SSH key conflicts
    If you use different SSH keys for different services (like GitHub and GitLab), you need to tell SSH which key to use for GitLab. Create or edit the ~/.ssh/config file with this content:

    Host gitlab.com
      HostName gitlab.com
      User git
      IdentityFile ~/.ssh/your-gitlab-key-file-name
    

    Save the file, then re-test the SSH connection.

  • Check for blocked SSH ports
    Some networks block the default SSH port (22). Try using port 443 instead by updating your ~/.ssh/config:

    Host gitlab.com
      HostName gitlab.com
      User git
      IdentityFile ~/.ssh/id_rsa
      Port 443
    

    Test with:

    ssh -T -p 443 git@gitlab.com
    

内容的提问来源于stack exchange,提问作者Kim Nicoli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 10:00:34