Linux下配置SSH无秘钥登录-演道网

本网站用的阿里云ECS,推荐大家用。自己搞个学习研究也不错
所谓公钥登录,就是用户将自己的公钥储存在远程主机上。登录的时候远程主机回向用户发送一段随机字符串,用户用自己的秘钥加密后再发送给远程主机。远程主机用事先储存的公钥进行解密,如果成功,就证明用户是可信的,直接允许登录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://go2live.cn

未经允许不得转载:演道网 » Linux下配置SSH无秘钥登录-演道网

赞 (0)
分享到:更多 ()

评论 0

评论前必须登录!

登陆 注册