在网络中设置 SSH 登录的循环方式

在网络中设置 SSH 登录的循环方式

我有一个由多个 linux/unix 盒子(各种 ubuntu、raspian 和 OS-X 盒子)组成的网络,我经常登录这些盒子。一般来说,我在 OSX 机器上,我生成了一个与每个盒子共享的密钥对,我可以使用该密钥对登录每个盒子。

我遇到的问题是尝试为其他盒子创建密钥对,以便当我需要在这些盒子之间直接复制文件时,因为大多数时候 MBP 都在 wifi 上,并且移动大文件的连接速度很慢。

举个简单的例子,我的 MBP 是计算机 A。Ubuntu #1 是计算机 B,Ubuntu #2 是计算机 C。

使用密钥对:
A可以登录B
A可以登录C

但B无法登录C,C也无法登录B

我得到的错误是“公钥”错误 权限被拒绝(公钥)。

我在任何地方搜索有关此错误的信息似乎都是使用多个密钥登录不同的盒子的情况。

我能想到的唯一方法是创建相同的密钥对,并将相同的公钥和私钥放在每台计算机上,但这似乎存在安全风险,将它们都放在一个位置。

编辑:

这就是更详细的情况(抱歉,我应该更彻底)

我从 A (MBP) 登录到 B (bbox),但无法登录到 C (sun)(从 B)。

我可以从 A 登录到 C,但不能(从 C)登录到 B。

madivad@bbox:~$ ssh sun
Permission denied (publickey).

出于同样的原因,我也无法推送公钥:

madivad@bbox:~$ ssh-copy-id sun
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/madivad/.ssh/id_rsa.pub"
/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: WARNING: All keys were skipped because they already exist on the remote system.
        (if you think this is a mistake, you may want to use -f option)

madivad@bbox:~$ ssh-copy-id -f sun
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/madivad/.ssh/id_rsa.pub"
Permission denied (publickey).
madivad@bbox:~$

那么让我们再次生成它(我已经做过无数次了):

madivad@bbox:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/madivad/.ssh/id_rsa):
/home/madivad/.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 /home/madivad/.ssh/id_rsa.
Your public key has been saved in /home/madivad/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:<removed> madivad@bbox
The key's randomart image is:
+---[RSA 2048]----+
|       So        |
|  beautiful it's |
|   a shame to    |
|    remove it    |
|    (although    |
|       it's      |
|   probably not  |
|     required)   |
+----[SHA256]-----+
madivad@bbox:~$ ssh-copy-id sun
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/madivad/.ssh/id_rsa.pub"
/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
Permission denied (publickey).
madivad@bbox:~$

我似乎在兜圈子

答案1

我得到的错误是“公钥”错误。

由于报告错误的方式如此精确,我只能说您在生成或部署密钥时在某个地方犯了错误。

您应该做的是通过运行命令在每台计算机上生成密钥对

ssh-keygen

然后,对于每对机器,以便您希望能够使用 X 上的密钥登录机器 Y,请在机器 X 上运行以下命令:

ssh-copy-id X

相关内容