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 [email protected]
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 [email protected]

确保目标主机上的 ~/.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 [email protected]
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 ~]#

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

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

相关推荐
独行soc37 分钟前
2025年渗透测试面试题总结-网络安全、Web安全、渗透测试笔试总结(一)(附回答)(题目+回答)
linux·运维·服务器·安全·web安全·面试·职场和发展
前进的程序员42 分钟前
Linux 驱动开发步骤及 SPI 设备驱动移植示例
linux·运维·驱动开发
m0_549314861 小时前
FPGA 不兼容故障及处理
运维·网络·fpga开发·硬件工程·cisco·硬件驱动
文牧之1 小时前
PostgreSQL 判断索引是否重建过的方法
运维·数据库·postgresql
cocogogogo2 小时前
配置Jupyter Notebook环境及Token认证(Linux服务器)
linux·服务器·jupyter
檀越剑指大厂3 小时前
【Docker系列】镜像大小排序
运维·docker·容器
木心3 小时前
Linux如何安装AppImage程序
linux
今天阳光明媚吗3 小时前
Linux线程
linux
小跌—3 小时前
Linux:认识基础IO
linux·运维·数据库
小米里的大麦3 小时前
007 Linux 开发工具(上)—— vim、解放sudo、gc+
linux·vim