【运维经】第38章——ssh免密登录授信

运维经–目录


ssh免密登录授信

1.应用场景
A主机经常登录B主机,又不想每次都输入密码。那么可以使用登录授信方式。

2.生成秘钥对

(base) frank@deepin:~/.ssh$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/frank/.ssh/id_rsa): 
/home/frank/.ssh/id_rsa already exists.
Overwrite (y/n)? 
(base) frank@deepin:~/.ssh$ ll
总用量 12
-rw------- 1 frank frank 1679 1月  22 12:05 id_rsa
-rw-r--r-- 1 frank frank  394 1月  22 12:05 id_rsa.pub
-rw-r--r-- 1 frank frank  222 1月  13 14:32 known_hosts
(base) frank@deepin:~/.ssh$

id_rsa # 秘钥
id_rsa.pub # 公钥

3.下发公钥

(base) frank@deepin:~/.ssh$ ssh-copy-id -i id_rsa.pub root@111.111.111.111
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
		(if you think this is a mistake, you may want to use -f option)

4.手动安装公钥
将A主机的~/.ssh/id_rsa.pub公钥文本内容,手动复制到B主机的~/.ssh/authorized_keys文件中

5.免密登录B主机

ssh root@111.111.111.111

不需要输入密码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夏 克

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值