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

简介: 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/51689041 1.
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/51689041
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了。


备注:

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


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




目录
相关文章
|
3月前
|
存储 分布式计算 资源调度
Hadoop小文件解决方案
Hadoop小文件解决方案
|
3月前
|
JavaScript 应用服务中间件 Linux
【应用服务 App Service】解决无法从Azure门户SSH登录问题
【应用服务 App Service】解决无法从Azure门户SSH登录问题
|
13天前
|
安全 Shell Linux
ssh密码忘记了怎么办
通过上述措施,不仅能够有效应对SSH密码遗忘的挑战,还能全方位加固SSH连接的安全,确保数据传输的无忧。
10 2
|
28天前
|
大数据 网络安全 数据安全/隐私保护
大数据-03-Hadoop集群 免密登录 超详细 3节点云 分发脚本 踩坑笔记 SSH免密 集群搭建(二)
大数据-03-Hadoop集群 免密登录 超详细 3节点云 分发脚本 踩坑笔记 SSH免密 集群搭建(二)
94 5
|
28天前
|
XML 大数据 网络安全
大数据-03-Hadoop集群 免密登录 超详细 3节点云 分发脚本 踩坑笔记 SSH免密 集群搭建(一)
大数据-03-Hadoop集群 免密登录 超详细 3节点云 分发脚本 踩坑笔记 SSH免密 集群搭建(一)
55 4
|
3月前
|
机器学习/深度学习 存储 Linux
【机器学习 Azure Machine Learning】使用VS Code登录到Linux VM上 (Remote-SSH), 及可直接通过VS Code编辑VM中的文件
【机器学习 Azure Machine Learning】使用VS Code登录到Linux VM上 (Remote-SSH), 及可直接通过VS Code编辑VM中的文件
|
3月前
|
安全 Shell Linux
如何禁止某个用户使用ssh登录
本文介绍了五种禁止用户通过SSH登录的方法:1) 修改`/etc/ssh/sshd_config`文件中的`DenyUsers`和`DenyGroups`来阻止特定用户或用户组登录;2) 将用户的默认shell设置为`/usr/sbin/nologin`或`/bin/false`以禁用其SSH访问;3) 利用PAM(可插入认证模块)通过编辑`/etc/security/sshd.conf`来限制登录权限;4) 通过编辑`/etc/hosts.deny`文件拒绝特定用户的SSH访问;5) 锁定或禁用用户账号以阻止所有类型的登录。每种方法都提供了详细的步骤指导。
344 1
|
3月前
|
存储 安全 测试技术
【超实用却暗藏杀机】sshpass:一键免密SSH登录的神器,为何生产环境却要敬而远之?探秘背后的安全隐患与替代方案!
【8月更文挑战第16天】sshpass 是一款便捷工具,可实现自动化SSH登录,简化脚本中的远程连接流程。通过后台自动处理密码输入,便于执行远程操作,如 `sshpass -p &#39;yourpassword&#39; ssh user@remotehost`。也可结合更多SSH选项使用,例如指定私钥文件。然而,因需明文传递密码,存在较大安全隐患,不适于生产环境;推荐使用公钥认证以增强安全性。
148 4
|
3月前
|
消息中间件 分布式计算 Hadoop
利用Hadoop进行实时数据分析的挑战与解决方案
【8月更文第28天】随着大数据技术的快速发展,企业和组织面临着越来越复杂的实时数据处理需求。Hadoop 作为一种分布式存储和处理大数据的框架,虽然擅长于批处理任务,但在处理实时数据流时存在一定的局限性。为了克服这些限制,Hadoop 经常与其他实时处理框架(如 Apache Kafka 和 Apache Storm)结合使用。本文将探讨如何利用 Hadoop 结合 Kafka 和 Storm 实现近实时的数据处理,并提供相关的代码示例。
344 0
|
3月前
|
安全 Linux Shell
Linux系统之间实现免密码登录(SSH无密码登录
【8月更文挑战第21天】要在Linux系统间实现SSH免密码登录,需先在源机器生成SSH密钥对,然后将公钥复制到目标机器的`.ssh/authorized_keys`文件中。可通过`ssh-keygen`命令生成密钥,并使用`ssh-copy-id`命令传输公钥。最后测试SSH连接,确保能无密码登录。若目标机器缺少相关目录或文件,需手动创建并设置适当权限。完成这些步骤后,即可实现安全便捷的免密码登录。
105 0

相关实验场景

更多