当前位置: 首页 > news >正文

Windows利用ssh免密码登录Linux

文章目录

    • 具体步骤
      • 1.Windows生成秘钥
      • 2.Windows配置config
      • 3.将公钥上传到Linux
      • 4.Linux将公钥内容添加到authorized_keys文件中
      • 5.Linux配置到sshd_config
      • 6.Windows测试连接


具体步骤

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

1.Windows生成秘钥

$ 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,指定远程服务器信息

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文件中

如果没有的话生成一下

cd /root/.ssh/
touch authorized_keys
cat id_rsa_txy2.pub >> authorized_keys

5.Linux配置到sshd_config

vim /etc/ssh/sshd_config

添加PubkeyAuthentication 参数

PubkeyAuthentication yes

重启服务

service ssh restart

6.Windows测试连接

用git bash连接

$ 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.

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

$ 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

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 应急响应-DDOS-典型案例
  • Jmeter接口测试断言详解
  • Windows 系统下 MongoDB和PostgreSQL数据库数据的备份和恢复
  • 使用Redis记录错误次数、序列号锁定和冻结时间的实现步骤示例[超详细]
  • WUP-MY-LABEL-PRINTER 旻佑热敏打印机标签打印uniapp插件使用说明
  • 革新测试管理:集远程、协同、自动化于一身的统一测试管理平台
  • Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data精读
  • Prometheus+Grafana保姆笔记(2)——监控Spring Boot微服务程序
  • 基于VS2022+Qt5+C++的串口助手开发
  • MySQL:复杂查询(二)——联合查询02
  • C语言之指针高级--指针操作二维整型、字符型数组、函数指针
  • vscode远程开发
  • C++:std::memory_order_relaxed(宽松内存序)
  • [Vue3] 9 其它API
  • Elasticsearch 搜索高亮功能及示例
  • 【划重点】MySQL技术内幕:InnoDB存储引擎
  • Codepen 每日精选(2018-3-25)
  • crontab执行失败的多种原因
  • es6
  • iOS仿今日头条、壁纸应用、筛选分类、三方微博、颜色填充等源码
  • Js基础知识(四) - js运行原理与机制
  • Js基础知识(一) - 变量
  • orm2 中文文档 3.1 模型属性
  • PHP 小技巧
  • React Native移动开发实战-3-实现页面间的数据传递
  • React的组件模式
  • Shell编程
  • Stream流与Lambda表达式(三) 静态工厂类Collectors
  • Webpack4 学习笔记 - 01:webpack的安装和简单配置
  • webpack项目中使用grunt监听文件变动自动打包编译
  • 程序员该如何有效的找工作?
  • 记录一下第一次使用npm
  • 类orAPI - 收藏集 - 掘金
  • 浏览器缓存机制分析
  • 如何解决微信端直接跳WAP端
  • 入门级的git使用指北
  • 线上 python http server profile 实践
  • 由插件封装引出的一丢丢思考
  • Spring第一个helloWorld
  • 扩展资源服务器解决oauth2 性能瓶颈
  • 蚂蚁金服CTO程立:真正的技术革命才刚刚开始
  • ​TypeScript都不会用,也敢说会前端?
  • ​低代码平台的核心价值与优势
  • # 手柄编程_北通阿修罗3动手评:一款兼具功能、操控性的电竞手柄
  • # 数据结构
  • (55)MOS管专题--->(10)MOS管的封装
  • (附源码)计算机毕业设计SSM基于java的云顶博客系统
  • (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间...
  • (十六)视图变换 正交投影 透视投影
  • (一)kafka实战——kafka源码编译启动
  • (一)Linux+Windows下安装ffmpeg
  • (原创)Stanford Machine Learning (by Andrew NG) --- (week 9) Anomaly DetectionRecommender Systems...
  • (终章)[图像识别]13.OpenCV案例 自定义训练集分类器物体检测
  • (转)甲方乙方——赵民谈找工作
  • **python多态