Windows利用ssh免密码登录Linux

文章目录


具体步骤

Windows利用ssh免密码登录Linux的具体步骤。

1.Windows生成秘钥

ssh 复制代码
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): /c/Users/Administrator/.ssh/id_rsa_txy2
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa_txy2
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa_txy2.pub
The key fingerprint is:
SHA256:9ap5t1EfhB7c91Kp1PnRLVrHfwqXodBXZaT9zabqe2M Administrator@DESKTOP-Q2BIJBU
The key's randomart image is:
+---[RSA 3072]----+
|               .*|
|           .. +*=|
|          o .=*BO|
|         . oo=+BO|
|        S   =o=.X|
|           . + *o|
|          . . o .|
|         o. .oE  |
|        o. o== . |
+----[SHA256]-----+

密钥:/c/Users/Administrator/.ssh/id_rsa_txy2

公钥:/c/Users/Administrator/.ssh/id_rsa_txy2.pub

2.Windows配置config

添加配置文件 C:\Users\Administrator.ssh\config,指定远程服务器信息

shell 复制代码
Host 106.52.2.19
HostName 106.52.2.19
User root
Port 22
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_txy2

3.将公钥上传到Linux

上传到 /root/.ssh/ 目录下面

4.Linux将公钥内容添加到authorized_keys文件中

如果没有的话生成一下

shell 复制代码
cd /root/.ssh/
touch authorized_keys
cat id_rsa_txy2.pub >> authorized_keys

5.Linux配置到sshd_config

shell 复制代码
vim /etc/ssh/sshd_config

添加PubkeyAuthentication 参数

shell 复制代码
PubkeyAuthentication yes

重启服务

ssh 复制代码
service ssh restart

6.Windows测试连接

用git bash连接

shell 复制代码
$ ssh root@106.52.2.19
Last failed login: Fri Aug 16 17:29:17 CST 2024 from 85.29.11.24 on ssh:notty
There were 3 failed login attempts since the last successful login.
Last login: Fri Aug 16 17:13:35 2024 from 223.104.6.71
[root@VM-20-2-centos ~]# exit
logout
Connection to 106.52.2.19 closed.

失败的话可能日志是这样的

shell 复制代码
$ ssh root@106.52.2.19
root@106.52.2.19's password:
Permission denied, please try again.
root@106.52.222.19's password:
Permission denied, please try again.
root@106.52.2.19's password:
root@106.52.2.19: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

参考:

SSH配置---Linux下实现免密码登录:https://www.cnblogs.com/hanwen1014/p/9048717.html

Windows(客户端)ssh免密码登录Linux(远程):https://blog.csdn.net/flytobj/article/details/86303050

相关推荐
努力努力再努力wz12 分钟前
【Linux网络系列】:JSON+HTTP,用C++手搓一个web计算器服务器!
java·linux·运维·服务器·c语言·数据结构·c++
峰顶听歌的鲸鱼8 小时前
Kubernetes介绍和部署
运维·笔记·云原生·容器·kubernetes·学习方法
物理与数学8 小时前
linux 内存分布
linux·linux内核
信创天地8 小时前
自动化运维利器赋能信创:Ansible与SaltStack在国产系统的部署与批量管理实战
运维·自动化·ansible
东城绝神9 小时前
《Linux运维总结:基于ARM64+X86_64架构使用docker-compose一键离线部署MySQL8.0.43 NDB Cluster容器版集群》
linux·运维·mysql·架构·高可用·ndb cluster
creator_Li9 小时前
即时通讯项目--(1)环境搭建
linux·运维·ubuntu
Ka1Yan9 小时前
Docker:基本概念与快速入门
运维·docker·容器
Mr'liu10 小时前
MongoDB 7.0 副本集高可用部署
linux·mongodb
文静小土豆11 小时前
Rocky Linux 二进制 安装K8S-1.35.0高可用集群
linux·运维·kubernetes
小技工丨11 小时前
华为TaiShan 200 2280 ARM服务器虚拟化部署完整指南
运维·服务器·arm开发