你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下配置SSH无秘钥登录

[日期:2017-07-06] 来源:Linux社区  作者:huanongying [字体: ]

所谓公钥登录,就是用户将自己的公钥储存在远程主机上。登录的时候远程主机回向用户发送一段随机字符串,用户用自己的秘钥加密后再发送给远程主机。远程主机用事先储存的公钥进行解密,如果成功,就证明用户是可信的,直接允许登录shell,不再要求密码。

[Hadoop@hadoop01 ~]$ cd .ssh
[hadoop@hadoop01 .ssh]$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[hadoop@hadoop01 .ssh]$ rm -rf ./*  #清空文件夹
[hadoop@hadoop01 .ssh]$ ssh-keygen -t rsa  #生成公钥和秘钥
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
a2:78:65:72:49:9a:71:91:aa:8f:3b:3e:a8:b3:74:87 hadoop@hadoop01.zjl.com
The key's randomart image is:
+--[ RSA 2048]----+
|      ..        |
|      ..        |
|    ..o          |
|    .* .        |
|  .+ * S        |
|  ...* .        |
| o.Eo.          |
|+ =.o            |
|++o+            |
+-----------------+
[hadoop@hadoop01 .ssh]$ ll
total 8
-rw-------. 1 hadoop hadoop 1675 Jun 19 23:41 id_rsa  #秘钥
-rw-r--r--. 1 hadoop hadoop  405 Jun 19 23:41 id_rsa.pub  #公钥

[hadoop@hadoop01 .ssh]$ ssh-copy-id hadoop02.zjl.com  #将公钥发送给远程主机
The authenticity of host 'hadoop01.zjl.com (192.168.0.131)' can't be established.
RSA key fingerprint is 60:10:35:2f:64:08:bf:82:e5:bc:56:8c:3d:60:18:13.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop01.zjl.com,192.168.0.131' (RSA) to the list of known hosts.
hadoop@hadoop01.zjl.com's password:
Now try logging into the machine, with "ssh 'hadoop01.zjl.com'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[hadoop@hadoop01 .ssh]$ ssh hadoop01.zjl.com  #无密码登录
 Last login: Mon Jun 19 23:30:46 2017 from 192.168.0.1
[hadoop@hadoop02 ~]$  #无密码登录成功

下面关于SSH相关的文章您也可能喜欢,不妨参考下:

Ubuntu 下配置 SSH服务全过程及问题解决 http://www.linuxidc.com/Linux/2011-09/42775.htm

Ubuntu 14.04 下安装Samba 及SSH 服务端的方法 http://www.linuxidc.com/Linux/2015-01/111971.htm

集群环境SSH免密码登录设置  http://www.linuxidc.com/Linux/2017-03/141296.htm

提高Ubuntu的SSH登陆认证速度的办法 http://www.linuxidc.com/Linux/2014-09/106810.htm

远程SSH连接服务与基本排错  http://www.linuxidc.com/Linux/2017-05/143738.htm

使用SSH公钥密钥自动登陆Linux服务器 http://www.linuxidc.com/Linux/2017-02/140642.htm

开启SSH服务让Android手机远程访问 Ubuntu 14.04  http://www.linuxidc.com/Linux/2014-09/106809.htm

SSH非交互式密码授权远程执行脚本  http://www.linuxidc.com/Linux/2017-04/143180.htm

SSH通过密钥登陆 http://www.linuxidc.com/Linux/2017-06/144997.htm

Linux上实现SSH免密码登陆远程服务器  http://www.linuxidc.com/Linux/2017-05/144165.htm

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-07/145450.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款