在網路中設定 SSH 登入的循環方式

在網路中設定 SSH 登入的循環方式

我有一個由多個 linux/unix 機器(各種 ubuntu、raspian 和 OS-X 機器)組成的網絡,我經常登入這些機器。一般來說,我在 OSX 機器上,我產生了一個與每個盒子共用的金鑰對,我可以使用該金鑰對登入每個盒子。

我遇到的問題是嘗試為其他盒子建立密鑰對,以便當我需要在這些盒子之間直接複製檔案時,因為大多數時候 MBP 都在 wifi 上,並且移動大檔案的連接速度很慢。

舉個簡單的例子,我的 MBP 是計算機 A。

使用金鑰對:
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

相關內容