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

Ubuntu 22桌面Bitbucket SSH认证需输入密码问题求助

SSH连接Bitbucket需输入密码问题排查

问题描述

已生成SSH密钥并添加至Bitbucket账户,但在Ubuntu 22桌面执行ssh -T git@bitbucket.org时,仍被要求输入密码。同一局域网内的Ubuntu 20笔记本无此问题。已排查/etc/hosts、HTTP_PROXY配置,确认无Bitbucket相关条目;多次重启电脑、确认仅运行单个SSH服务,问题仍存在。

调试日志(ssh -Tv git@bitbucket.org)

(base) pi@pi:~/Downloads$ ssh -Tv git@bitbucket.org
OpenSSH_8.9p1 Ubuntu-3ubuntu0.4, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /home/pi/.ssh/config
debug1: /home/pi/.ssh/config line 1: Applying options for bitbucket.org
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to bitbucket.org [::1] port 22.  # 关键异常点:连接到本地回环地址
debug1: Connection established.
debug1: identity file /home/pi/.ssh/bitbucket type 3
debug1: identity file /home/pi/.ssh/bitbucket-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.4  # 远程服务为本地SSH,而非Bitbucket
debug1: compat_banner: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to bitbucket.org:22 as 'git'
debug1: load_hostkeys: fopen /home/pi/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:zBaRJxidxS95rF36rYX+4dVY8vxsPFXeTaoe/jY0l5o
debug1: load_hostkeys: fopen /home/pi/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'bitbucket.org' is known and matches the ED25519 host key.
debug1: Found key in /home/pi/.ssh/known_hosts:4
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: agent returned 2 keys
debug1: Will attempt key: /home/pi/.ssh/bitbucket ED25519 SHA256:UuoiiBi82VGqZKqrN1DpeWADDFK14fhaxqxWlEn3JSQ explicit agent
debug1: Will attempt key: my@email.address ED25519 SHA256:MSZGD5k5hgQ5iHLH+50Tgca9IjupA4Zvr50NxRR6JaE agent
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com>
debug1: kex_input_ext_info: publickey-hostbound@openssh.com=<0>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/pi/.ssh/bitbucket ED25519 SHA256:UuoiiBi82VGqZKqrN1DpeWADDFK14fhaxqxWlEn3JSQ explicit agent
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: my@email.address ED25519 SHA256:MSZGD5k5hgQ5iHLH+50Tgca9IjupA4Zvr50NxRR6JaE agent
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
git@bitbucket.org's password: 

已确认信息

已将bitbucket.pub公钥内容正确添加至Bitbucket账户(ED25519算法):

ssh-ed25519 ASXAC3NzaC1lZDI1NTE5MAAAIAi+AtlfwCRjTFEAORlZsj96TFGKhWDAXlvgflhaqr1L my@email.address

私钥格式正常(已脱敏):

b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQMAACAIvgLZX8AkY0xSADkZWbI/ekxRioVgwF5b4H5YWqq9lwAJAJis7Hv3rOx7
9wAAAAtzc2gtZWQyNTUxOQAAACAIvgLZX8AkY0xRADkZWbI/ekxRioVgwF5b4H5YWqq9lw
AAAEC3+U4odV1//Kljf1SOWrdJUwqUFC+VkTV6aweA6nWCtAi+AtlfwCRjTFEAORlZsj96
TFGKhWDAXlvgsrhaqr2XAAAADln1YWkuM0Bvc3UuZWR1AQIDBAUGBw==
-----END OPENSSH PRIVATE KEY-----

问题根源

从调试日志的debug1: Connecting to bitbucket.org [::1] port 22可明确:系统将bitbucket.org解析到了IPv6本地回环地址(::1),相当于连接本地SSH服务而非真实的Bitbucket服务器。本地SSH服务无法识别你的Bitbucket密钥,因此会要求输入密码。

解决步骤

  1. 验证DNS解析结果
    执行以下命令检查bitbucket.org的解析IP:

    nslookup bitbucket.org
    # 或
    dig bitbucket.org
    

    正常应返回Bitbucket的公网IP(如18.205.93.0、18.234.32.150等),而非::1或127.0.0.1。

  2. 清空本地DNS缓存
    Ubuntu 22使用systemd-resolved,执行以下命令清空缓存:

    sudo systemd-resolve --flush-caches
    

    之后重新测试解析和SSH连接。

  3. 排查本地DNS劫持

    • 检查是否安装了本地DNS服务(如dnsmasq),确认其配置未篡改bitbucket.org的解析。
    • 检查浏览器插件、系统安全工具等是否存在DNS拦截或篡改功能。
  4. 临时修复:手动指定IP到hosts
    若DNS解析问题无法快速解决,可临时在/etc/hosts中添加Bitbucket的真实IP:

    1. 获取真实IP:
      dig bitbucket.org +short
      
    2. 编辑/etc/hosts:
      sudo nano /etc/hosts
      
    3. 添加一行(替换真实IP为上一步获取的地址):
      真实IP bitbucket.org
      
    4. 保存后测试ssh -T git@bitbucket.org。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 19:27:36