码迷,mamicode.com
首页 > 系统相关 > 详细

linux下免密登录

时间:2020-04-02 16:12:34      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:error:   ide   The   dom   rand   already   public   http   ssh   

建议修改一下主机名

centos7

#修改主机名为bigdata

hostnamectl  set-hostname bigdata

##重启服务器,验证主机名是否生效

hostname

 

hosts表设置

技术图片

 

 

 将hosts文件  复制到各个主机

scp hosts root@ip:/etc/

生产密钥

通过命令”ssh-keygen -t rsa“

[root@node129 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
fd:48:77:c0:fb:24:14:e4:82:41:21:30:93:e5:cc:80 root@node129
The key‘s randomart image is:
+--[ RSA 2048]----+
|   .=+o.+. .o    |
|  E .B . o o .   |
|      + . . =    |
|         . o o   |
|        S o + o  |
|         . + =   |
|          . . .  |
|                 |
|                 |
+-----------------+
  

  

密钥生成之后 放在用户目录下 即

/root/.ssh

该目录下的文件说明

authorized_keys:存放远程免密登录的公钥,主要通过这个文件记录多台机器的公钥

 id_rsa : 生成的私钥文件

 id_rsa.pub : 生成的公钥文件

 know_hosts : 已知的主机公钥清单 

 

如果希望ssh公钥生效需满足至少下面两个条件:

1) .ssh目录的权限必须是700

 2) .ssh/authorized_keys文件权限必须是600

设置免密登录的方法之一:

ssh-copy-id -i ~/.ssh/id_rsa.pub 172.16.161.12(目标ip)

 

[root@node129 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub 172.16.161.12
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: ERROR: ssh: connect to host 172.16.161.12 port 22: No route to host

[root@node129 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub 172.16.161.128
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.16.161.128‘s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh ‘172.16.161.128‘"
and check to make sure that only the key(s) you wanted were added.

[root@node129 ~]# ssh node128
Last login: Thu Apr  2 15:00:52 2020 from node127
[root@node128 ~]# 

  

 

 

linux下免密登录

标签:error:   ide   The   dom   rand   already   public   http   ssh   

原文地址:https://www.cnblogs.com/l7planet/p/12620032.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!