通常在过去,我总是在必要时通过我的 SSH 公钥手动复制到遥控器。我在 Mac 上,我最终决定开始使用ssh-copy-id来简化我的生活,所以我只使用自制软件来安装它。
我只是第一次使用ssh-copy-id并且对结果有点困惑。
在我的本地机器上,查看我的id_rsa.pub密钥时,它以username@machinename结尾。我喜欢这个,它可以很容易地识别我以后可以在远程机器上删除的键。
我只是在本地机器上使用ssh-copy-id将我的公钥移动到远程,然后查看了远程上的authorized_keys文件。我注意到在远程而不是我的公钥以myusername@mymachinename结尾(如预期的那样)它现在以/Users/myusername/.ssh/id_rsa 结尾?
为什么会出现差异?有没有办法强制 ssh-copy-id像在我的本地机器上那样使用username@machinename?
一般来说,这可能只是我对 SSH 和密钥的误解,但有什么想法值得赞赏吗?
编辑:
刚刚发现这只发生在我排除我的身份文件并假设默认值时。
基本上,如果我只这样做:ssh-copy-id user@hostname然后我在遥控器的authorized_keys文件中得到这个尴尬的评论。
如果我指定我的公钥:ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostname那么一切都按预期复制,按预期使用myusername@machinename?!
是什么导致了这种奇怪?下面的链接说它应该总是默认使用我的id_rsa.pub文件,所以我不需要指定它来获得对遥控器的正确评论吗?http://linux.die.net/man/1/ssh-copy-id
-i
运行时添加选项ssh-copy-id
。这在手册中有解释:
Default behaviour without -i, is to check if 'ssh-add -L' provides any
output, and if so those keys are used. Note that this results in the
comment on the key being the filename that was given to ssh-add(1) when
the key was loaded into your ssh-agent(1) rather than the comment con-
tained in that file, which is a bit of a shame. Otherwise, if ssh-add(1)
provides no keys contents of the default_ID_file will be used.
Run Code Online (Sandbox Code Playgroud)