key位置 win10生成的ssh_Windows 10:如何在OpenSSH中生成SSH密钥

通过生成自己的安全密钥,进一步扩展Microsoft在Windows 10中的OpenSSH实现。

图片来源:www.ghost580.com

OpenSSH的使用无处不在,通过网络安全访问客户端设备。 SSH的目的很简单:在两个端点之间安全地封装管理流量,在这种情况下使用服务器 - 客户端模型进行身份验证。

虽然可以启用SSH以使用连接到同一域的客户端(例如使用Active Directory凭据),但在尝试与网络交换机或路由器等设备进行通信时,这是不可能的,这些设备本身不是任何域基础结构的一部分。相反,这些设备和基于Linux的客户端使用公钥/私钥对来验证用户是否尝试连接到客户端并在提供远程访问之前执行身份验证。

在本文中,我们将使用此用例,因为它通常被认为是一种更安全的获取访问方法,它可以无缝地适用于Windows和非Windows设备。通过生成和管理SSH密钥对,IT将能够以安全的方式远程连接到客户端,同时确保每个用户的机密性和不可否认性,使用与个人Windows登录帐户绑定的唯一密钥对进行安全存储。

为PowerShell安装OpenSSH模块

1.使用管理员级帐户登录Windows计算机,然后使用管理员权限启动PowerShell。

2.输入以下cmdlet以安装OpenSSH模块。 如果这是第一次在设备上安装模块,系统可能会提示您下载并安装一些其他工具。 键入“Y”以允许安装工具。

Install-Module -Force OpenSSHUtils

3.接下来,输入cmdlet以启动ssh-agent服务,以安全地存储私有生成的SSH密钥。

Start-Service ssh-agent

4.最后,输入cmdlet以启动sshd服务,该服务将自动生成第一对主机密钥。

Start-Service sshd

注意:默认情况下,未安装OpenSSH Server应用程序,因此必须先安装它。 此外,ssh-agent服务设置为Disabled,必须在上面的cmdlet工作之前更改。 主机密钥存储在%HOMEDRIVE% ProgramData ssh目录中。

生成用户密钥对

1.在PowerShell中,将目录更改为存储SSH密钥的上面的路径,然后输入下面的cmdlet以生成密钥对。

SSH-凯基

2.为了生成一组唯一的密钥对并存储它们,系统将提示您提供存储密钥对的目录,或者您可以按Enter键选择提供的默认位置。

3.接下来,系统将提示您选择密码来加密密钥对。 虽然提供密码是可选的,但强烈建议输入密码,因为当使用密钥对建立远程连接时,它可以作为双因素身份验证的第二个目的。

4.一旦完成该过程,将在SHA256指纹旁边生成两个文件,并且该密钥的随机艺术图像将显示在屏幕上,并且应如下所示(图A):

图A.

安全地复制公钥

OpenSSH工具包括SCP和SFTP实用程序,可以使传输密钥完全安全。为了正确配置Windows客户端以通过SSH密钥进行身份验证,必须将公钥(.PUB)文件传输到客户端设备的.ssh目录并存储在authorized_keys文本文件中。

1.通过在PowerShell中执行以下命令开始此过程,以在用户的​​配置文件文件夹中创建.ssh目录。

ssh username@domain.com mkdir C: Users username .ssh

2.使用SCP实用程序,输入以下命令以将公钥从服务器安全地复制到客户端设备。

scp C: Users username .ssh id_rsa.pub username@domain.com:C: Users username .ssh authorized_keys

3.最后,通过输入以下命令修改服务器上authorized_keys文件的ACL。

ssh —% username@domain.com powershell -c $ConfirmPreference = 'None'; Repair-AuthorizedKeyPermission C:Usersusername.sshauthorized_keys

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenSSH_9.2p1 Debian-2, OpenSSL 3.0.9 30 May 2023 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to lxslc702.ihep.ac.cn [2401:de00:2:332::186] port 22. debug1: Connection established. debug1: identity file /home/fyf/.ssh/id_rsa type -1 debug1: identity file /home/fyf/.ssh/id_rsa-cert type -1 debug1: identity file /home/fyf/.ssh/id_ecdsa type -1 debug1: identity file /home/fyf/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/fyf/.ssh/id_ecdsa_sk type -1 debug1: identity file /home/fyf/.ssh/id_ecdsa_sk-cert type -1 debug1: identity file /home/fyf/.ssh/id_ed25519 type -1 debug1: identity file /home/fyf/.ssh/id_ed25519-cert type -1 debug1: identity file /home/fyf/.ssh/id_ed25519_sk type -1 debug1: identity file /home/fyf/.ssh/id_ed25519_sk-cert type -1 debug1: identity file /home/fyf/.ssh/id_xmss type -1 debug1: identity file /home/fyf/.ssh/id_xmss-cert type -1 debug1: identity file /home/fyf/.ssh/id_dsa type -1 debug1: identity file /home/fyf/.ssh/id_dsa-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_9.2p1 Debian-2 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4 debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x04000006 debug1: Authenticating to lxslc702.ihep.ac.cn:22 as 'fanyufan' debug1: load_hostkeys: fopen /home/fyf/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /home/fyf/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ssh-ed25519 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY Connection closed by 2401:de00:2:332::186 port 22
07-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值