关闭

[Hadoop]SSH免密码登录以及失败解决方案

标签: SSH免密码登陆失败解决rsa
10388人阅读 评论(0) 收藏 举报
分类:
1. 创建ssh-key

这里我们采用rsa方式,使用如下命令:

  1. xiaosi@xiaosi:~$ ssh-keygen -t rsa -f ~/.ssh/id_rsa
  2. Generating public/private rsa key pair.
  3. Created directory '/home/xiaosi/.ssh'.
  4. Enter passphrase (empty for no passphrase):
  5. Enter same passphrase again:
  6. Your identification has been saved in /home/xiaosi/.ssh/id_rsa.
  7. Your public key has been saved in /home/xiaosi/.ssh/id_rsa.pub.
  8. The key fingerprint is:
  9. SHA256:n/sFaAT94A/xxxxxxxxxxxxxxxxxxxxxxx xiaosi@xiaosi
  10. The key's randomart image is:
  11. +---[xxxxx]----+
  12. |        o= .. .. |
  13. |        o.= ..  .|
  14. |         *.* o  .|
  15. |        +.4.=E+..|
  16. |       .SBo=. h+ |
  17. |        ogo..oo. |
  18. |          or +j..|
  19. |          ...+o=.|
  20. |          ... o=+|
  21. +----[xxxxx]-----+

备注:

这里会提示输入pass phrase,一定不要输入任何字符,回车即可。

2. 生成authorized_keys文件
  1. xiaosi@xiaosi:~$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

备注:

记得要把authorized_keys文件放到.ssh目录下,与rsa等文件放在一起,否则免登录失败,debug如下(ssh -vvv localhost进行调试,查找错误原因):

  1. xiaosi@xiaosi:~$ ssh -vvv localhost
  2. OpenSSH_7.2p2 Ubuntu-4ubuntu1, OpenSSL 1.0.2g-fips 1 Mar 2016
  3. debug1: Reading configuration data /etc/ssh/ssh_config
  4. debug1: /etc/ssh/ssh_config line 19: Applying options for *
  5. debug2: resolving "localhost" port 22
  6. debug2: ssh_connect_direct: needpriv 0
  7. debug1: Connecting to localhost [127.0.0.1] port 22.
  8. debug1: Connection established.
  9. debug1: identity file /home/xiaosi/.ssh/id_rsa type 1
  10. debug1: key_load_public: No such file or directory
  11. debug1: identity file /home/xiaosi/.ssh/id_rsa-cert type -1
  12. debug1: key_load_public: No such file or directory
  13. debug1: identity file /home/xiaosi/.ssh/id_dsa type -1
  14. debug1: key_load_public: No such file or directory
  15. debug1: identity file /home/xiaosi/.ssh/id_dsa-cert type -1
  16. debug1: key_load_public: No such file or directory
  17. debug1: identity file /home/xiaosi/.ssh/id_ecdsa type -1
  18. debug1: key_load_public: No such file or directory
  19. debug1: identity file /home/xiaosi/.ssh/id_ecdsa-cert type -1
  20. debug1: key_load_public: No such file or directory
  21. debug1: identity file /home/xiaosi/.ssh/id_ed25519 type -1
  22. debug1: key_load_public: No such file or directory
  23. debug1: identity file /home/xiaosi/.ssh/id_ed25519-cert type -1
  24. debug1: Enabling compatibility mode for protocol 2.0
  25. debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu1
  26. debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu1
  27. debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu1 pat OpenSSH* compat 0x04000000
  28. debug2: fd 3 setting O_NONBLOCK
  29. debug1: Authenticating to localhost:22 as 'xiaosi'
  30. debug3: hostkeys_foreach: reading file "/home/xiaosi/.ssh/known_hosts"
  31. debug3: record_hostkey: found key type ECDSA in file /home/xiaosi/.ssh/known_hosts:1
  32. debug3: load_hostkeys: loaded 1 keys from localhost
  33. debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
  34. debug3: send packet: type 20
  35. debug1: SSH2_MSG_KEXINIT sent
  36. debug3: receive packet: type 20
  37. debug1: SSH2_MSG_KEXINIT received
  38. debug2: local client KEXINIT proposal
  39. debug2: KEX algorithms: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,ext-info-c
  40. debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
  41. debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
  42. debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
  43. debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
  44. debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
  45. debug2: compression ctos: none,zlib@openssh.com,zlib
  46. debug2: compression stoc: none,zlib@openssh.com,zlib
  47. debug2: languages ctos:
  48. debug2: languages stoc:
  49. debug2: first_kex_follows 0
  50. debug2: reserved 0
  51. debug2: peer server KEXINIT proposal
  52. debug2: KEX algorithms: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
  53. debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
  54. debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
  55. debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
  56. debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
  57. debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
  58. debug2: compression ctos: none,zlib@openssh.com
  59. debug2: compression stoc: none,zlib@openssh.com
  60. debug2: languages ctos:
  61. debug2: languages stoc:
  62. debug2: first_kex_follows 0
  63. debug2: reserved 0
  64. debug1: kex: algorithm: curve25519-sha256@libssh.org
  65. debug1: kex: host key algorithm: ecdsa-sha2-nistp256
  66. debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
  67. debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
  68. debug3: send packet: type 30
  69. debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
  70. debug3: receive packet: type 31
  71. debug1: Server host key: ecdsa-sha2-nistp256 SHA256:378enl3ckhdpObP8fnsHr1EXz4d1q2Jde+jUplkub/Y
  72. debug3: hostkeys_foreach: reading file "/home/xiaosi/.ssh/known_hosts"
  73. debug3: record_hostkey: found key type ECDSA in file /home/xiaosi/.ssh/known_hosts:1
  74. debug3: load_hostkeys: loaded 1 keys from localhost
  75. debug1: Host 'localhost' is known and matches the ECDSA host key.
  76. debug1: Found key in /home/xiaosi/.ssh/known_hosts:1
  77. debug3: send packet: type 21
  78. debug2: set_newkeys: mode 1
  79. debug1: rekey after 134217728 blocks
  80. debug1: SSH2_MSG_NEWKEYS sent
  81. debug1: expecting SSH2_MSG_NEWKEYS
  82. debug3: receive packet: type 21
  83. debug2: set_newkeys: mode 0
  84. debug1: rekey after 134217728 blocks
  85. debug1: SSH2_MSG_NEWKEYS received
  86. debug2: key: /home/xiaosi/.ssh/id_rsa (0x5602df5e80c0)
  87. debug2: key: /home/xiaosi/.ssh/id_dsa ((nil))
  88. debug2: key: /home/xiaosi/.ssh/id_ecdsa ((nil))
  89. debug2: key: /home/xiaosi/.ssh/id_ed25519 ((nil))
  90. debug3: send packet: type 5
  91. debug3: receive packet: type 7
  92. debug1: SSH2_MSG_EXT_INFO received
  93. debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
  94. debug3: receive packet: type 6
  95. debug2: service_accept: ssh-userauth
  96. debug1: SSH2_MSG_SERVICE_ACCEPT received
  97. debug3: send packet: type 50
  98. debug3: receive packet: type 51
  99. debug1: Authentications that can continue: publickey,password
  100. debug3: start over, passed a different list publickey,password
  101. debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
  102. debug3: authmethod_lookup publickey
  103. debug3: remaining preferred: keyboard-interactive,password
  104. debug3: authmethod_is_enabled publickey
  105. debug1: Next authentication method: publickey
  106. debug1: Offering RSA public key: /home/xiaosi/.ssh/id_rsa
  107. debug3: send_pubkey_test
  108. debug3: send packet: type 50
  109. debug2: we sent a publickey packet, wait for reply
  110. debug3: receive packet: type 51
  111. debug1: Authentications that can continue: publickey,password
  112. debug1: Trying private key: /home/xiaosi/.ssh/id_dsa
  113. debug3: no such identity: /home/xiaosi/.ssh/id_dsa: No such file or directory
  114. debug1: Trying private key: /home/xiaosi/.ssh/id_ecdsa
  115. debug3: no such identity: /home/xiaosi/.ssh/id_ecdsa: No such file or directory
  116. debug1: Trying private key: /home/xiaosi/.ssh/id_ed25519
  117. debug3: no such identity: /home/xiaosi/.ssh/id_ed25519: No such file or directory
  118. debug2: we did not send a packet, disable method
  119. debug3: authmethod_lookup password
  120. debug3: remaining preferred: ,password
  121. debug3: authmethod_is_enabled password
  122. debug1: Next authentication method: password
  123. xiaosi@localhost's password:

3. 验证
  1. xiaosi@xiaosi:~$ ssh localhost
  2. The authenticity of host 'localhost (127.0.0.1)' can't be established.
  3. ECDSA key fingerprint is SHA256:378enl3ckhdpObP8fnsHr1EXz4d1q2Jde+jUplkub/Y.
  4. Are you sure you want to continue connecting (yes/no)? yes
  5. Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
  6. sign_and_send_pubkey: signing failed: agent refused operation
  7. xiaosi@localhost's password:
4. authorized_keys权限

我们可以看到还是让我输入密码,很大可能是authorized_keys文件权限的问题,我们给该文件赋予一定权限:

  1. xiaosi@xiaosi:~$ chmod 600 ~/.ssh/authorized_keys
再次验证:
  1. xiaosi@xiaosi:~$ ssh localhost
  2. Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-24-generic x86_64)
  3. * Documentation:  https://help.ubuntu.com/
  4. 0 个可升级软件包。
  5. 0 个安全更新。
  6. Last login: Thu Jun 16 08:05:50 2016 from 127.0.0.1

到此表示OK了。


备注:

或者第一次需要输入密码,以后再次登陆就不需要输入密码了。


有更明白的小伙伴可以指导一下。。。。。。




5
0
查看评论

hadoop设置ssh免密码登录

对于需要远程管理其它机器,一般使用远程桌面或者telnet。linux一般只能是telnet。但是telnet的缺点是通信不加密,存在不安全因素,只适合内网访问。为 解决这个问题,推出了通信加密通信协议,即SSH(Secure Shell)。使用非对称加密方式,传输内容使用rsa或者dsa加密,可以...
  • zwx19921215
  • zwx19921215
  • 2014-02-21 21:59
  • 16395

hadoop 配置集群之间SSH无密码登陆 (重点推荐)

在"Hadoop集群(第1期)"安装CentOS6.0时,我们选择了一些基本安装包,所以我们需要两个服务:ssh和rsync已经安装了。可以通过下面命令查看结果显示如下:   rpm –qa | grep openssh ...
  • jihuanliang
  • jihuanliang
  • 2015-08-31 00:23
  • 3925

Hadoop集群SSH服务和免密码登录的配置

前言: SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定;SSH 为建立在 应用层和传输层基础上的安全协议。SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的 协议。 在Hadoop集群或...
  • ITYang_
  • ITYang_
  • 2017-04-12 16:21
  • 3301

完全分布式hadoop集群搭建(含SSH免密码登录)(详细版)

  • 2015-09-10 19:50
  • 399KB
  • 下载

hadoop学习笔记(五)——全分布模式下SSH免密码登陆的实现

因为三个节点要相互访问,所以,三个节点都是客户端,也都是服务器端,我们分别在三个节点上创建一对密钥文件,密钥文件包括公钥文件(~/.ssh/id_rsa.pub)和私钥文件 (~/.ssh/id_rsa)。 客户端在使用ssh登录到其他节点上的时候,ssh会发送私钥去和其他节点上的公钥去匹配,如果匹...
  • thinkpadshi
  • thinkpadshi
  • 2015-06-16 15:14
  • 4047

ssh 无密码验证 及 ssh localhost 仍然需要密码的解决方案

1、安装ssh 直接 sudo apt-get install
  • hackerwin7
  • hackerwin7
  • 2014-06-02 15:44
  • 22565

ssh无密码登录认证失败

问题现象: serverA机器已经生产rsa密钥 且已经将public key添加到serverB机器/root/.ssh/authorized_keys 但是ssh root@135.251.208.141机器时仍然需要输入密码,即无密码认证失败 分析与处理: 用ssh -v debug...
  • jacky0922
  • jacky0922
  • 2014-01-08 14:00
  • 24974

配置ssh公钥后免密码ssh登录失败

在公司的服务器上配置过ssh公钥,之前一直可以免密码登录。但是最近登录时,每次都提示要输入密码。尝试了删除known_hosts,重新把id_rsa.pub添加到服务器~/.ssh/authorized_keys下也没有用。 通过查看系统的登录验证日志文件/var/log/auth.log,看到每...
  • feiniao8651
  • feiniao8651
  • 2017-03-07 12:02
  • 1112

linux设置SSH免密码登录,但登录不成功

相关资料 http://blog.csdn.net/shiqidide/article/details/7582572 http://www.xuebuyuan.com/1583179.html 配置 CentOS6.7 OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 1...
  • qq_19648191
  • qq_19648191
  • 2017-02-03 10:54
  • 3602

linux 配置ssh无密码登录不起作用的解决方案

1、安装ssh 直接 sudo apt-get install openssh-server 2、查看ssh运行状态  ps -e | grep ssh 如果发现 sshd 和 ssh-agent 即表明 ssh服务基本运行正常 3、生成公钥和私钥 ssh-keygen -t ...
  • u010533843
  • u010533843
  • 2017-02-08 14:45
  • 2832
    个人资料
    • 访问:1512068次
    • 积分:22551
    • 等级:
    • 排名:第378名
    • 原创:624篇
    • 转载:133篇
    • 译文:60篇
    • 评论:189条
    博客专栏
    文章分类
    最新评论