首页 > 其他分享 >服务器之间建立互信,免密登录SSH

服务器之间建立互信,免密登录SSH

时间:2022-11-18 09:48:05浏览次数:39  
标签:免密 rsa 192.168 SSH key root id 服务器之间 ssh

生成SSH KEY

[root@kafaka3 ~]# cd /root/.ssh
[root@kafaka3 .ssh]# pwd
/root/.ssh
[root@kafaka .ssh]# ssh-keygen	#生成秘钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):	#输入秘钥名(默认id_rsa)
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:
a7:82:b2:ce:c2:e0:21:7d:4e:63:7c:03:d5:3c:98:25 root@kafaka
The key's randomart image is:
+--[ RSA 2048]----+
|      E*.        |
|      +.+        |
|     .   .       |
|    .            |
| . . .  S .      |
|o.. *.o  o       |
|= o=.o...        |
|.+ o.  .         |
| o+              |
+-----------------+
[root@kafaka .ssh]# ls -l
total 8
-rw------- 1 root root 1675 Jul 13 20:12 id_rsa
-rw-r--r-- 1 root root  393 Jul 13 20:12 id_rsa.pub

复制到另外两台机器上

[root@kafaka .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
The authenticity of host '192.168.56.152 (192.168.56.152)' can't be established.
ECDSA key fingerprint is e6:c4:48:fa:0d:76:3e:2c:3b:60:e7:61:90:ad:9a:ee.
Are you sure you want to continue connecting (yes/no)? yes
/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
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
[root@kafaka .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
The authenticity of host '192.168.56.153 (192.168.56.153)' can't be established.
ECDSA key fingerprint is e6:c4:48:fa:0d:76:3e:2c:3b:60:e7:61:90:ad:9a:ee.
Are you sure you want to continue connecting (yes/no)? yes
/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
[email protected]'s password:

Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

修改kafka2 & kafka3目录和文件的权限。如果不修改,可能无法正常免密登录成功

  • kafka2文件权限修改
    [root@kafaka2 .ssh]# chmod 700 ~/.ssh
    [root@kafaka2 .ssh]# chmod 600 ~/.ssh/authorized_keys
  • kafka3文件权限修改
    [root@kafaka3 .ssh]# chmod 700 ~/.ssh
    [root@kafaka3 .ssh]# chmod 600 ~/.ssh/authorized_keys

免密登录测试

[root@kafaka .ssh]# ssh 192.168.56.152
Last login: Tue Jul 13 20:04:08 2021 from 192.168.56.1
[root@kafaka2 ~]# exit
logout
Connection to 192.168.56.152 closed.

标签:免密,rsa,192.168,SSH,key,root,id,服务器之间,ssh
From: https://www.cnblogs.com/qds1401744017/p/16902152.html

相关文章

  • 转 - Ubuntu 无法进行SSH连接,开启22端口
      我们在VM中安装好Ubuntu虚拟机后,经常需要使用Xshell等工具进行远程连接,但是会出现无法连接的问题,原因是Ubuntu中默认关闭了SSH服务。1、查看Ubuntu虚拟机IP地......
  • weblogic免密登录使用nohup启动密码无效问题
    目录weblogic免密登录使用nohup启动密码无效问题1、密码重置1.1、使用一下命令可以重置weblogic的密码,注意后面有一个点,前面还有一个空格1.2、将生成的文件DefaultAuthenti......
  • 使用ssh链接访问docker容器
    需求:  通过ssh链接docker容器 基础镜像-Centos:例:#拉取centos镜像dockerpullcentos#启动一个并访问centos容器dockerrun-itcentos/bin/bash ......
  • openssh允许root用户登录
    sudovi/etc/ssh/sshd_config对于允许root账号登录,找到PermitRootLogin项将其值改为yes,即可(如果其前有#注释则去掉#)//允许root用户登陆PermitRootLoginyes当然最后......
  • 解决ubuntu 下 SSH无法连接的问题
    刚安装的ubuntu20默认是没有安装sshd服务器的,所以无法远程。1.修改root密码先用普通登录sudo-i切换为rootpasswd修改root密码2.检查是否开启SSH服务ps-e|grep......
  • windows操作系统配置github的SSH免密登录
    一、生成ssh秘钥前提条件:安装OpenSSH进入用户家目录,打开cmd终端输入ssh-keygen,一路回车生成终端输入命令typeid_rsa.pub查看公钥内容并复制内容二、将复制的公钥内容......
  • ssh、scp通过跳板机
    SSHssh-Juser@jumpboxuser@target-hostssh-Jjumpbox1jumpbox2jumpbox3target-hostSCPdownloadscp-P22-o'ProxyJumpjumpbox'-rtarget-host:target-di......
  • mac电脑安装secureCrt,secureCrt如何登录ssh
    mac软件下载:SecureCRTformac(终端SSH工具)关闭sip使用最新版本SecureFX和SecureCRT不能在同一个路径下破解激活,可以分别安装在两个不同的目录下使用。比如一个安装在......
  • linux SSH配置
    linuxSSH配置1、简介SSH(SecureShell,安全外壳)是一种网络安全协议,通过加密和认证机制实现安全的访问和文件传输等业务。传统远程登录或文件传输方式,例如Telnet、FTP,使用......
  • MAC ssh登录远程主机报错:Someone could be eavesdropping on you right now (man-in-t
    1@WARNING:REMOTEHOSTIDENTIFICATIONHASCHANGED!@23@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@45ITISPOSSIBLETHAT......