Linux 配置SSH互信

最简单的一种形式配置主机间的互信,假设有两台主机A、B,A作为客户端,B作为目标机,可以做如下配置:

在A客户端设置:

bash 复制代码
➜  ~ ssh-keygen -t rsa -b 2048 -f my_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in my_key
Your public key has been saved in my_key.pub
The key fingerprint is:
SHA256:Ls8NyhrXtrCZQ2lNU+h4E7MPpWu4BjtSo15ZOPSRIo0 xxx@xxxx.local
The key's randomart image is:
+---[RSA 2048]----+
|         .       |
|   o   .+ o      |
|  E + oo B       |
|   o +..X        |
|    o o*S*       |
|    ++=o+ .      |
|   o+*+o=        |
|  o.o++@ +       |
| ....+*.+ .      |
+----[SHA256]-----+
➜  ~

将公钥分发到主机B

bash 复制代码
ssh-copy-id root@192.168.86.129

确保目标主机上的 ~/.ssh/authorized_keys 文件的权限为 600

bash 复制代码
chmod 600 ~/.ssh/authorized_keys

设置 SSH 服务

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

修改如下

bash 复制代码
PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile      .ssh/authorized_keys

重启ssh服务

bash 复制代码
systemctl restart sshd

验证免登录

bash 复制代码
➜  ~ ssh root@192.168.86.129
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sun Dec 29 21:19:23 2024 from 192.168.86.1
[root@localhost ~]#

这是最基础,最简单的用法。

当然更加规范的用法是在互信机器之外为用户(注意,是为用户,不是为某个机器)生成密钥,比如说密钥中心等,这里就不再展开说了

相关推荐
likfishdn8 分钟前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean27 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=29 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
北京耐用通信1 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
sz66cm2 小时前
Linux基础 -- ARM 32 位架构动态注入代码技术文档
linux·arm开发·架构