Windows 配置 SSH 免密登录 Linux 服务器

SSH PowerShell Git About 1,049 words

免密登录

只需要使用如下命令即可直接登录服务器Shell窗口,无需输入密码。

ssh root@192.168.1.100

解决方法

使用ssh-keygen生成id_rsa私钥,id_rsa.pub公钥,生成的文件在%HOMEPATH%/.ssh用户目录下的.ssh文件夹中。

ssh-keygen.exe

使用Git Bash命令行执行ssh-copy-id,将公钥拷贝到需要登录的服务器,指定用户名和IP地址。

也可以直接复制id_rsa.pub中的内容,粘贴到目标服务器的~/.ssh/目录下的authorized_keys文件(authorized_keys文件没有可以新建)。

ssh-copy-id -i ./id_rsa.pub root@192.168.1.100

输出

$ ssh-copy-id -i ./id_rsa.pub root@192.168.1.100
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "./id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.1.100's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.1.100'"
and check to make sure that only the key(s) you wanted were added.

确认

登录目标服务器,在~/.ssh/目录下是否存在authorized_keys文件。

authorized_keys文件中的内容与Windows推送上去的id_rsa.pub一致。

这样就可以在Windows上直接使用ssh root@192.168.1.100连接目标服务器了,无需再输入密码。

Views: 3,271 · Posted: 2022-06-29

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh