关于ssh连接主机,git连接github失败的问题:ssh -T git@github.com&&Permission denied (publickey)

本文介绍了一种常见的SSH连接GitHub失败的情况,详细分析了错误信息并提供了具体的解决方案,包括检查公钥配置、调整密钥文件名等步骤。
关于ssh连接主机,git连接github失败的问题
	问题:$ ssh -T git@github.com
		Permission denied (publickey)

解析:
	1、可以看出问题出在publickey(公钥)
	2、接着ssh -T -v git@github.com 看下具体信息

penSSH_6.1p1 Debian-4, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.252.131] port 22.
debug1: Connection established.
debug1: identity file /home/sunny/.ssh/id_rsa type -1
debug1: identity file /home/sunny/.ssh/id_rsa-cert type -1
debug1: identity file /home/sunny/.ssh/id_dsa type -1
debug1: identity file /home/sunny/.ssh/id_dsa-cert type -1
debug1: identity file /home/sunny/.ssh/id_ecdsa type -1
debug1: identity file /home/sunny/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1+github5
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1+github5 pat OpenSSH_5*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.1p1 Debian-4
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/sunny/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/sunny/.ssh/id_rsa
debug1: Trying private key: /home/sunny/.ssh/id_dsa
debug1: Trying private key: /home/sunny/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

	3、可以发现在一下几行出现问题:
	debug1: Next authentication method: publickey
 	debug1: Trying private key: /home/sunny/.ssh/id_rsa
  	debug1: Trying private key: /home/sunny/.ssh/id_dsa
   	debug1: Trying private key: /home/sunny/.ssh/id_ecdsa
    debug1: No more authentication methods to try.
	Permission denied (publickey).

	4、发现它一直在查找id_rsa、id_dsa、id_ecdsa这三个文件,然后就不尝试其他了;
	5、我们查看下 ~/.ssh文件夹下的文件:ls ~/.ssh
		github  github.pub ...
	这里没有第4步出现的文件,github是创建ssh-key时输入的名字

	6、现在我们让~/.ssh文件夹下,还原当初没有改时的名字id_rsa
		cp github id_rsa && cp gitbub.pub id_rsa.pub

	7、再次尝试连接:ssh -T git@github.com
	Hi xxx ! You've successfully authenticated, but GitHub does not provide shell access.成功。
总结:
	运用shh -T -v git@github.com查看具体出错信息,再根据信息来调试

转载请注明出处:http://blog.csdn.net/sunnypotter/article/details/18948053

在 Windows 操作系统中使用 `ssh -T git@github.com` 命令出现 `git@github.com: Permission denied (publickey).` 错误,可尝试以下解决办法: #### 检查 SSH 密钥是否存在 进入 `~/.ssh` 文件夹(Windows 的路径为 `C://用户/你的用户名/.ssh/`,在 Git Bash 中可使用 `cd ~/.ssh` 进入)查看是否存在 SSH 密钥文件(通常为 `id_rsa` 和 `id_rsa.pub`)[^4]。 ```bash cd ~/.ssh ls ``` #### 重新生成 SSH 密钥 若 SSH 密钥不存在或有问题,可重新生成。在 Git Bash 中运行以下命令: ```bash ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` 在生成过程中会提示设置密码短语,可根据需求选择是否设置。 #### 将公钥添加到 GitHub 账户 生成 SSH 密钥后,需要将公钥(`id_rsa.pub` 文件内容)添加到 GitHub 账户。在 Git Bash 中使用以下命令复制公钥内容: ```bash clip < ~/.ssh/id_rsa.pub ``` 然后登录 GitHub 账户,进入 `Settings` -> `SSH and GPG keys` -> `New SSH key`,将复制的公钥内容粘贴到 `Key` 字段,点击 `Add SSH key` 保存。 #### 测试通过 HTTPS 端口的 SSH 是否可行 运行以下 SSH 命令: ```bash ssh -T -p 443 git@ssh.github.com ``` 若这样有效,则可以覆盖 SSH 设置以强制与 GitHub.com 的任何连接均通过该服务器和端口运行。在 SSH 配置文件(`~/.ssh/config`)中添加以下部分: ```plaintext Host github.com Hostname ssh.github.com Port 443 User git ``` 若 `~/.ssh/config` 中没有 `config` 文件,可以自己创建一个无后缀的 `config` 文件。最后再次测试连接: ```bash ssh -T git@github.com ``` #### 检查 SSH 代理 确保 SSH 代理正在运行,并将私钥添加到代理中: ```bash eval $(ssh-agent -s) ssh-add ~/.ssh/id_rsa ```
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值