求助 SSH -vT git@github.com 命令报错

2014-11-20 19:00:33 +08:00
 vitozhang
在使用ssh命令测试能否登陆github服务器的时候出现Permission deny,麻烦各位给分析分析是啥原因
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Connecting to github.com [192.30.252.130] port 22.
debug1: Connection established.
debug1: identity file /.ssh/identity type -1
debug1: identity file /.ssh/id_rsa type -1
debug1: identity file /.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
debug1: no match: libssh-0.6.0
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-sha1 none
debug1: kex: client->server aes128-cbc hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /.ssh/known_hosts:1
Warning: Permanently added the RSA host key for IP address '192.30.252.130' to t
he list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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: /.ssh/identity
debug1: Trying private key: /.ssh/id_rsa
debug1: Trying private key: /.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
5064 次点击
所在节点    程序员
10 条回复
paulw54jrn
2014-11-20 19:04:42 +08:00
找不到private key..

把private key命名为id_rsa, 放在$HOME/.ssh/试一试
vitozhang
2014-11-20 19:05:37 +08:00
初步确定问题出在
debug1: identity file /.ssh/identity type -1
debug1: identity file /.ssh/id_rsa type -1
debug1: identity file /.ssh/id_dsa type -1
系统找不到路径 /.ssh/
这是什么原因呢
vitozhang
2014-11-20 19:06:48 +08:00
@paulw54jrn 忘了跟你说了,我的是win8系统,private key已经放到 用户名/.ssh 目录了
paulw54jrn
2014-11-20 19:11:34 +08:00
@vitozhang
Windows下不熟悉.. 你是在Cygwin里面ssh的妈?
paulw54jrn
2014-11-20 19:13:12 +08:00
根据http://weka.wikispaces.com/Where+is+my+home+directory+located%3F

on Windows, open a command-prompt and type the following command
echo %USERPROFILE%
on Cygwin, open a bash and type the following command
echo $USERPROFILE

如果是Cygwin的话, 放在 $USERPROFILE/.ssh/ 试试
aa65535
2014-11-20 19:37:01 +08:00
到 git 安装目录下去找 ssh_config 这个文件(一般是 /etc/ssh 下面),改成
IdentityFile=~/.ssh/id_rsa
注意有个 ~
Ge4Los
2014-11-20 20:28:36 +08:00
如果用cygwin的话, 先要在环境变量里面先定义下HOME
然后把id_rsa 放在 ~/.ssh/ 的目录下
vitozhang
2014-11-21 09:54:28 +08:00
@paulw54jrn

@aa65535

@Ge4Los
我使用的MinGW,不过跟这个没关系,Git安装目录自带了个ssh以及.ssh目录,我把系统用户名目录下的.ssh 的内容拷贝到Git安装目录下的.ssh中就可以了。不过我还是没找到ssh_config文件,不知道该怎么设置ssh命令默认的private key的存放位置。
aa65535
2014-11-21 10:37:12 +08:00
@vitozhang Ctrl + F 搜索一下,一般是在 Git 安装目录 下的 etc/ssh 中,或者 MinGW 下的 etc/ssh 中,没有可以新建一个。
Host *
  StrictHostKeyChecking no
  UserKnownHostsFile=/dev/null
  IdentityFile=~/.ssh/id_rsa

可以在 http://git-scm.com/downloads 下载一个, 也是 MinGW 的。
vitozhang
2014-11-21 13:29:35 +08:00
@aa65535 在Git安装目录下的etc/ssh目录中添加了ssh_config文件, 并添为所有Host添加IdentityFile=~/.ssh/id_rsa
但ssh依然将路径解释为 /.ssh/id_rsa,完全忽略了~。
添加环境变量 HOME,设置为C:/Users/myname,然后将设置身份文件为IdentityFile=$HOME/.ssh/id_rsa发现奏效。另外,如果发现直接设置绝对路径/c/Users/myname/.ssh/id_rsa也是可以的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/148085

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX