秘钥管理

Windows

参考: https://learn.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_keymanagement

1 介绍

ssh-keygen,用于生成安全的密钥
ssh-agent 和 ssh-add,用于安全地存储私钥
scp 和 sftp,在首次使用服务器时安全地复制公钥文件
使用power shell

2 启用openssh

# Set the sshd service to be started automatically
Get-Service -Name sshd | Set-Service -StartupType Automatic

# Now start the sshd service
Start-Service sshd
# 由于没有与 sshd 服务关联的用户,因此主机密钥存储在 C:\ProgramData\ssh 下。
# 添加用户秘钥,-t选择加密方式
ssh-keygen -t ed25519

3 秘钥代理

# By default the ssh-agent service is disabled. Allow it to be manually started for the next step to work.
# Make sure you're running as an Administrator.
Get-Service ssh-agent | Set-Service -StartupType Manual
# Set-Service ssh-agent -StartupType Automatic 
# Start the service
Start-Service ssh-agent

# This should return a status of Running
Get-Service ssh-agent

# Now load your key files into ssh-agent
ssh-add ~\.ssh\id_ed25519

4 注册服务

# 注意Get-Service ssh-agent已经注册了这个服务,Set-Service ssh-agent -StartupType Automatic 设置服务自动启动
New-Service -Name ssh-agent -BinaryPathName "C:\Windows\System32\OpenSSH\ssh-agent.exe" -StartupType Automatic
posted @ 2023-05-25 09:39  hs3434  阅读(27)  评论(0编辑  收藏  举报