我试图以管理员用户的身份将客户机密钥从Linux(Ubuntu)复制到Windows服务器。
到目前为止,我可以通过以下步骤实现这一点:
我在linux中使用bash,在windows中使用powershell 7.3.4作为管理员。
scp ~/.ssh/public_key.pub Admin@WindowsServer:__PROGRAMDATA__/ssh/administrators_authorized_keys文件是否存在于C:\PROGRAMDATA\SSH\中,如果没有,请创建: New-Item -Force -Path c:\PROGRAMDATA\ssh\administrators_authorized_keysicacls C:\PROGRAMDATA\ssh\administrators_authorized_keys /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"Get-Content C:\ProgramData\ssh\public_key.pub | Add-Content C:\ProgramData\ssh\administrators_authorized_keys中administrators_authorized_keys文件,我正在尝试让一个不同的linux客户机将它的公钥附加到这个windows服务器(配置了administrators_authorized_keys )中,使用一行scp .。
我试过这样的方法:
scp Linux2Win_key.pub Admin@WindowsServer:__ProgramData__/ssh/ ; Get-Content C:\ProgramData\ssh\Linux2Win_key.pub | Add-Content C:\ProgramData\ssh\administrators_authorized_keys
公钥文件被复制,但没有附加到administrator_authorized_keys文件中。出了一个错误:
-bash: Add-Content: command not found
-bash: Get-Content: command not found
然后我试了一下:scp Linux2Win_key.pub Admin@WindowsServer:__ProgramData__/ssh/ ; cat __ProgramData__/ssh/Linux2Win_key.pub >> __ProgramData__/ssh/administrators_authorized_keys
类似的结果是,会复制公钥文件,但不将其附加到administrator_authorized_keys文件。出了一个错误:
-bash: __ProgramData__/ssh/administrators_authorized_keys: No such file or directory
思想:
看起来scp只能复制文件,ssh拷贝id不能在windows中工作,尽管openssh可以启用,ssh可以在windows中使用。
如果您知道在windows中将公钥附加到authorized_keys或administrators_authorized_keys的更好方法(而不是手工操作),请共享。谢谢
我知道,这更像是窗户问题,我已经试着去问其他地方了。
我很抱歉,如果它冒犯了任何人,我在linux/unix中介绍了这个问题。
发布于 2023-04-20 01:34:20
好像我只是漏掉了引号!
当使用scp命令时,在Admin@WindowsServer:之后,内容必须是引号。
scp Linux2Win_key.pub Admin@WindowsServer:'__ProgramData__/ssh/ ; Get-Content C:\ProgramData\ssh\Linux2Win_key.pub | Add-Content C:\ProgramData\ssh\administrators_authorized_keys'这对我有用。
https://unix.stackexchange.com/questions/743477
复制相似问题