无法使用 ssh-copy-id 复制公钥(错误:没有此文件)

无法使用 ssh-copy-id 复制公钥(错误:没有此文件)

我正在尝试在本地主机上使用 ssh-copy-id 命令将 pub 文件复制到远程主机使用这些说明

user@local-host:~$ ssh-copy-id -i ~/.ssh/id_rsa_Tran.pub username@ipAddress

我可以确认我的 .ssh 文件夹中有 pub 文件(截图链接)
不幸的是,当我尝试运行该命令时出现错误:

/usr/bin/ssh-copy-id: ERROR: failed to open ID file '/home/user/.ssh/id_rsa_Tran': No such file
    (to install the contents of '/home/user/.ssh/id_rsa_Tran.pub' anyway, look at the -f option) 

我检查了-f 选项但我不知道是否应该使用它。为什么它不能找到我 .ssh 目录中的文件?

答案1

如果你仔细观察,它正在试图找到一个不同的文件——它试图找到私钥通常与 .pub 文件相邻的文件,用于检查密钥是否已经存在。

您没有私钥,只有公钥,所以您别无选择,只能使用该-f选项跳过此检查。

答案2

.pub如果您已经创建了密钥对,则无需使用指定公钥ssh-copy-id

pg@TREX:~$ ls .ssh
authorized_keys  id_rsa      known_hosts      ssh_config
config           id_rsa.pub  known_hosts.old  ssh_config_orig
pg@TREX:~$ 
pg@TREX:~$ ssh-copy-id -i .ssh/id_rsa 192.168.1.202
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".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
[email protected]'s password: 

Number of key(s) added: 1

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

pg@TREX:~$ ssh 192.168.1.202
Linux MediaRasPi 6.1.19-v8+ #1637 SMP PREEMPT Tue Mar 14 11:11:47 GMT 2023 aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Apr  5 09:14:01 2023 from 192.168.1.222

Wi-Fi is currently blocked by rfkill.
Use raspi-config to set the country before use.

pg@MediaRasPi:~ $ 

相关内容