如何将ssh密钥添加到远程服务器?

cqc*_*991 6 linux ssh ssh-keys

在我的VPS中,运行ssh-add -l并返回:The agent has no identities. 但我cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'之前已经运行过

我然后运行ssh-add ~/.ssh/authorized_keys 它返回@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for '/home/deployer/.ssh/authorized_keys' are too open. It is recommended that your private key files are NOT accessible by others. This private key will be ignored.

ssh git@github.com仍然得到报告Permission denied (publickey).

小智 11

目前投票最多的答案显然是错误的,因为它无法理解问题。OP 询问如何在远程服务器上授权密钥,而不是如何向本地 ssh-agent 添加密钥。

要将密钥添加到远程服务器,请使用ssh-copy-id本地 PC 上的命令:

ssh-copy-id -i path/to/key.pub username@remoteHost
Run Code Online (Sandbox Code Playgroud)

这增加了位于公共密钥path/to/key.pub与正确的许可服务器在remoteHost使用username登录名称。请注意,这似乎还需要公钥旁边的私钥(path/to/key本示例中的文件)。


小智 8

要将ssh-key添加到ssh-agent,您必须添加以下内容:

ssh-add
Run Code Online (Sandbox Code Playgroud)

之后确保添加了您的密钥:

ssh-add -l
Run Code Online (Sandbox Code Playgroud)

要修复您的权限问题,请尝试:

chmod 0600 ~/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)