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

相关推荐
fiveym1 小时前
PXE安装Debian报错:GRUB安装失败排查指南
运维·debian
张小姐的猫2 小时前
【Linux】多线程 —— 线程同步 | 生产者消费者模型 | POSIX 信号量
linux·运维·服务器
handler012 小时前
【MySQL】教你库与表的增删查改操作(基础)
运维·数据库·笔记·sql·mysql·数据·分析
biter down3 小时前
12:参数化测试,一套用例批量跑 N 组数据
运维·python
十年一梦实验室3 小时前
【ChatGPT】阳极氧化线 Global SI 自动化系统深度拆解、爆炸图10张、信息图10张、C++代码框架
运维·自动化
Harm灬小海4 小时前
【云计算学习之路】学习Centos7系统-Linux下用户及组管理
linux·运维·服务器·学习·云计算
扛枪的书生4 小时前
HAProxy 学习总结
linux
herinspace4 小时前
管家婆辉煌主机登录提示“连接失败,请确认输入正确的服务器名”
运维·服务器·学习·零售·管家婆软件·财务软件
日取其半万世不竭4 小时前
Linux 云服务器磁盘扩容:从分区到文件系统的完整流程
java·linux·服务器
byxdaz4 小时前
Linux 系统中常用的日志查看命令
linux·运维