Windows10安装OpenSSH客户端并生成SSH Key

2021-07-28 1576点热度 0人点赞 0条评论

现在Git提交代码都流行用SSH Key密钥来登录了,登录Linux客户端也可以使用SSH密码登录,不用输入密码,确实比较方便。

免密码登录Linux的文章,请看:https://blog.terrynow.com/2021/02/05/linux-ssh-none-password-ie-key-file-login/

安装OpenSSH客户端

不过Windows下可能没有默认安装SSH相关的工具,我们可以使用管理员权限打开命令提示符看下:

输入ssh,提示使用方法,就说明是安装好了SSH,如果提示命令未找到,就要手动安装了,现在Windows10的自带程序里就已经集成了OpenSSH客户端了,安装起来也是非常简单。

Microsoft Windows [版本 10.0.17763.1935]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Windows\system32>ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
           [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
           [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
           [-i identity_file] [-J [user@]host[:port]] [-L address]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-Q query_option] [-R address] [-S ctl_path] [-W host:port]
           [-w local_tun[:remote_tun]] destination [command]

C:\Windows\system32>

如果未找到ssh命令,可以尝试这样安装:

  1. Windows左下角点右键-进行程序和功能
  2. 看下是否安装了OpenSSH客户端
  3. 如果没有安装,点击『添加功能』,然后安装OpenSSH客户端就OK了,如下图所示:

微软官网更详细的安装步骤:https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse

生成SSH Key密钥对

我们需要生成SSH Key密钥对,这就相当于生成一张门卡,以后你用这张门卡登记需要登录的Linux客户端或者Git服务器,来进行Linux的SSH登录和Git的提交。

同样管理员状态下打开命令提示符,输入ssh-keygen,一路下一步,就能生成SHA256格式的密钥对了。

C:\Windows\system32>ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Terry/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\Terry/.ssh/id_rsa.
Your public key has been saved in C:\Users\Terry/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:oUrxILpwpNr57GWYOsyKj4IByaWKEI8fsWBFBAoIS3o terry@DESKTOP-0FT29OM
The key's randomart image is:
+---[RSA 2048]----+
|=o=+             |
|Oo..             |
|**Eoo   .        |
|=B+. + . .       |
|O.... o S        |
|*+.o +           |
|++o + o          |
|+.++ o           |
|=ooo+            |
+----[SHA256]-----+

C:\Windows\system32>

这样在你的用户名 C:\Users\Terry/.ssh下,就生成了id_rsa和id_rsa.pub两个文件,其中id_rsa是私钥,id_rsa.pub是公钥,所以是一对,平时需要登录Linux的SSH或者添加到Git,都只需要将公钥(id_rsa.pub)文件的内容(用记事本打开复制下来就可以)传给Linux或者Git网页管理后台。

使用

 

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论