免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 12825 | 回复: 27
打印 上一主题 下一主题

SSH 无密码登录服务器的问题【已解决】 [复制链接]

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-22 19:44 |只看该作者 |倒序浏览
本帖最后由 smallfish 于 2011-03-23 17:51 编辑


//是客户端用户权限的问题,不能设置成777,设置成755,700都可以!



弄了一下午了,不知道咋搞的,每次登录到远程服务器都要输入密码。

本地服务器A,远程服务器B,现在需要实现从A到 B 不管是SSH还是SCP都不需要密码。使用的是普通用户

A:

[scpdb@host .ssh]$ssh-keygen -t
Generating public/private rsa key pair.
Enter file in which to save the key (/home/scpdb/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/scpdb/.ssh/id_rsa.
Your public key has been saved in /home/scpdb/.ssh/id_rsa.pub.
The key fingerprint is:
e5:6e:0a:30:ea:70:73:99:37:5e:29:6a:7f:8b:16:39 scpdb@host.com



[scpdb@host .ssh]$ssh-copy-id -i ./id_rsa scpdb@B


[scpdb@host .ssh]$ssh scpdb@B
scpdb@B.comm's password:

DEBUG 信息如下:

OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to B.com [5.6.7.8] port 22.
debug1: Connection established.
debug3: Not a RSA1 key file /home/scpdb/.ssh/id_rsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/scpdb/.ssh/id_rsa type 1
debug1: loaded 1 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_init: found hmac-md5
debug1: kex: server->client aes128-cbc hmac-md5 none
debug2: mac_init: found hmac-md5
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 127/256
debug2: bits set: 502/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: filename /home/scpdb/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 1
debug3: check_host_in_hostfile: filename /home/scpdb/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 1
debug1: Host 'myhive-b.aerohive.com' is known and matches the RSA host key.
debug1: Found key in /home/scpdb/.ssh/known_hosts:1
debug2: bits set: 531/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/scpdb/.ssh/id_rsa (0x2b735699aff0)
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-with-mic,password
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug3: Trying to reverse map address 5.6.7.8.
debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/scpdb/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
scpdb@B.com's password:

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
2 [报告]
发表于 2011-03-22 19:54 |只看该作者
id_rsa内容:


-----BEGIN RSA PRIVATE KEY-----
MIIEogIBA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NYt4DwECtLZGp
8jLmGcFOwN3wyEwEJyzaV5uKykjvaQ0sPd9+NHRvgbBtKPMSck/vw7b7EH6C5U4g
0BIu4O8ZO6JaSHaEX3Xzm4k12A6kwF9LOtcLnaIvX/0RFiuJwOXfsNQzTiyKTBBa
7ochPGOCQGBuBKZyAS2S3wKBgHPi4AmmjxG/xH7w5U0jV/7Mok69cltyoeR+t01O
RNAvtTphzz7YLclLOcf4CYStDbakOMMxl6VS+sqaG4ujusx5Sk1I+yeYvXcNMxl7
9y5reqve+ju1cgYwCRWq5+PZ/XTDaVY/RoD7jxzhRU9SAWF/wojesEpdB4Z/TLL/
bjNTAoGADkfvXChaSAgDeRRI0g9TsotwSy+OxQBjslWrwxVWsLJtftoAPBDZbSe9
kkKfxy1N8zykslcvzNVdZzLlszXKGSK6kv0j0fzmFyXobA6C53608ssPHSAjU39O
QBwdXw0nHr6tulBR0237h50PXcTFXN1HHn21m5oLGjSI2/pKfgE=
-----END RSA PRIVATE KEY-----

论坛徽章:
0
3 [报告]
发表于 2011-03-22 19:59 |只看该作者
回复 1# smallfish


    这个 先 把相关的目录 key 都删除掉   重新做次!

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
4 [报告]
发表于 2011-03-22 20:05 |只看该作者
做了好多次了呢。。。

论坛徽章:
0
5 [报告]
发表于 2011-03-22 20:09 |只看该作者
回复 4# smallfish


    做法对吗?               客户端的 公钥发到远程服务器      .ssh/id_rsa.pub

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
6 [报告]
发表于 2011-03-22 20:41 |只看该作者
回复  smallfish


    做法对吗?               客户端的 公钥发到远程服务器      .ssh/id_rsa.pub
taojie2000 发表于 2011-03-22 20:09



    谢谢!我用了2种方式,把公钥发送到远程服务器,都尝试过:

1.[scpdb@host .ssh]$ssh-copy-id -i ./id_rsa scpdb@B

2.scp id_rsa.pub scpdb@B:/home/scpdb/.ssh/authorized_keys

论坛徽章:
0
7 [报告]
发表于 2011-03-22 20:58 |只看该作者
回复 6# smallfish


    ssh-copy-id  -i  ./id_rsa.pub   到服务器

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
8 [报告]
发表于 2011-03-22 22:13 |只看该作者
我就是这么弄的,呵呵

论坛徽章:
0
9 [报告]
发表于 2011-03-22 22:29 |只看该作者
回复 8# smallfish


    ./id_rsa   你命令里是这个啊?    你打错了?

论坛徽章:
0
10 [报告]
发表于 2011-03-22 22:30 |只看该作者
回复 8# smallfish


    sshd_config
    PasswordAuthentication no   这里呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP